remove bug that would cause input reading to stop if an error was encountered
This commit is contained in:
20
gosh.go
20
gosh.go
@@ -110,16 +110,20 @@ func (gosh *Goshell) Open(r *bufio.Reader) {
|
|||||||
for {
|
for {
|
||||||
// start a goroutine to get input from the user
|
// start a goroutine to get input from the user
|
||||||
go func(ctx context.Context, input chan<- string) {
|
go func(ctx context.Context, input chan<- string) {
|
||||||
// TODO: future enhancement is to capture input key by key
|
for {
|
||||||
// to give command granular notification of key events.
|
// TODO: future enhancement is to capture input key by key
|
||||||
// This could be used to implement command autocompletion.
|
// to give command granular notification of key events.
|
||||||
fmt.Fprintf(ctx.Value("gosh.stdout").(io.Writer), "%s ", api.GetPrompt(loopCtx))
|
// This could be used to implement command autocompletion.
|
||||||
line, err := r.ReadString('\n')
|
fmt.Fprintf(ctx.Value("gosh.stdout").(io.Writer), "%s ", api.GetPrompt(loopCtx))
|
||||||
if err != nil {
|
line, err := r.ReadString('\n')
|
||||||
fmt.Fprintf(ctx.Value("gosh.stderr").(io.Writer), "%v\n", err)
|
if err != nil {
|
||||||
|
fmt.Fprintf(ctx.Value("gosh.stderr").(io.Writer), "%v\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
input <- line
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
input <- line
|
|
||||||
}(loopCtx, line)
|
}(loopCtx, line)
|
||||||
|
|
||||||
// wait for input or cancel
|
// wait for input or cancel
|
||||||
|
|||||||
Reference in New Issue
Block a user