File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,10 +30,12 @@ func init() {
3030 init8086 ()
3131}
3232
33+ var ma machine
34+
3335func main () {
3436 //machineName := keyX64
3537 //machineName := keyX86
36- var arch = flag .String ("a" , "x86 " , "x86/x64/8086" )
38+ var arch = flag .String ("a" , "x64 " , "x86/x64/8086" )
3739 flag .Parse ()
3840 var machineName string
3941 switch * arch {
@@ -43,11 +45,11 @@ func main() {
4345 fallthrough
4446 case key8086 :
4547 machineName = * arch
46-
4748 default :
4849 fmt .Println ("invalid arch type" )
4950 }
50- ma , ok := machineMap [machineName ]
51+ var ok bool
52+ ma , ok = machineMap [machineName ]
5153 if ! ok {
5254 fmt .Println ("wrong key" )
5355 os .Exit (1 )
@@ -56,17 +58,16 @@ func main() {
5658 ma .displayRegisters ()
5759 ma .displayStack ()
5860
59- for {
60- fmt .Println ("Input q to quit." )
61- // FIXME when input ctrl+c/ctrl+z/ctrl+d
62- // prompt will become very slow
63- t := prompt .Input (machineName + "> " , completer )
64- if t == "q" || t == "quit" || t == "exit" {
65- break
66- }
67- ma .execute (t )
68- ma .displayRegisters ()
69- ma .displayStack ()
70- }
61+ p := prompt .New (myExecutor , completer , prompt .OptionPrefix (machineName + ">> " ))
62+ p .Run ()
63+
64+ }
7165
66+ func myExecutor (cmd string ) {
67+ if cmd == "quit" || cmd == "exit" || cmd == "q" {
68+ os .Exit (0 )
69+ }
70+ ma .execute (cmd )
71+ ma .displayRegisters ()
72+ ma .displayStack ()
7273}
You can’t perform that action at this time.
0 commit comments