Commit a893df8 1 parent 14afe7b commit a893df8 Copy full SHA for a893df8
File tree 1 file changed +10
-6
lines changed
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -114,24 +114,28 @@ func (r *REPL) Prompt() {
114
114
for {
115
115
var command string
116
116
fmt .Fprint (r .out , PromptInit )
117
- select {
118
- case <- r .Interrupted :
119
- r .Cmd ["exit" ].Run ()
120
- default :
117
+ waitPrompt := make (chan struct {})
118
+ go func (prompt chan struct {}) {
119
+ defer func () { close (prompt ) }()
121
120
// read first space-delimited string (the command).
122
121
_ , err := fmt .Fscanf (r .in , "%s" , & command )
123
122
if err != nil {
124
123
if err == io .EOF {
125
- command = "exit"
124
+ command = CmdExit
126
125
}
127
126
}
128
127
command = strings .TrimSpace (command )
129
128
if cmd , ok := r .Cmd [command ]; ok {
130
129
cmd .Run ()
131
130
} else {
132
131
r .Errorf ("Unrecognised command: %s\n " , command )
133
- r .Cmd ["help" ].Run ()
132
+ r .Cmd [CmdHelp ].Run ()
134
133
}
134
+ }(waitPrompt )
135
+ select {
136
+ case <- r .Interrupted : // Wait for Ctrl+C
137
+ r .Cmd [CmdExit ].Run ()
138
+ case <- waitPrompt : // Wait for prompt to finish
135
139
}
136
140
}
137
141
}
You can’t perform that action at this time.
0 commit comments