From a22fdcd72d83ef64ebc352d14efddd575fff4692 Mon Sep 17 00:00:00 2001 From: Gavin Date: Tue, 15 Oct 2019 03:04:41 -0400 Subject: [PATCH] remove bug that would cause input reading to stop if an error was encountered --- gosh.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gosh.go b/gosh.go index 84c7b6f..953e113 100644 --- a/gosh.go +++ b/gosh.go @@ -110,16 +110,20 @@ func (gosh *Goshell) Open(r *bufio.Reader) { for { // start a goroutine to get input from the user go func(ctx context.Context, input chan<- string) { - // TODO: future enhancement is to capture input key by key - // to give command granular notification of key events. - // This could be used to implement command autocompletion. - fmt.Fprintf(ctx.Value("gosh.stdout").(io.Writer), "%s ", api.GetPrompt(loopCtx)) - line, err := r.ReadString('\n') - if err != nil { - fmt.Fprintf(ctx.Value("gosh.stderr").(io.Writer), "%v\n", err) + for { + // TODO: future enhancement is to capture input key by key + // to give command granular notification of key events. + // This could be used to implement command autocompletion. + fmt.Fprintf(ctx.Value("gosh.stdout").(io.Writer), "%s ", api.GetPrompt(loopCtx)) + line, err := r.ReadString('\n') + if err != nil { + fmt.Fprintf(ctx.Value("gosh.stderr").(io.Writer), "%v\n", err) + continue + } + + input <- line return } - input <- line }(loopCtx, line) // wait for input or cancel