diff --git a/input_posix.go b/input_posix.go index 8c7631d..13834de 100644 --- a/input_posix.go +++ b/input_posix.go @@ -138,9 +138,7 @@ func (ip *InputProcessor) Run(ctx context.Context) (err error) { log.Printf("[ERROR] cannot read %s", err) return err } - if !(len(b) == 1 && b[0] == 0) { - ip.UserInput <- b - } + ip.UserInput <- b } } } diff --git a/input_windows.go b/input_windows.go index c66af25..9d3ff12 100644 --- a/input_windows.go +++ b/input_windows.go @@ -84,13 +84,11 @@ func (ip *InputProcessor) Run(ctx context.Context) (err error) { select { case <-ctx.Done(): return + case <-ip.Pause: + // Ignore on windows. default: b, err := ip.in.Read() - if err != nil { - log.Printf("[ERROR] cannot read %s", err) - return err - } - if !(len(b) == 1 && b[0] == 0) { + if err == nil && !(len(b) == 1 && b[0] == 0) { ip.UserInput <- b } continue diff --git a/output_windows.go b/output_windows.go index 2508b0d..d60b573 100644 --- a/output_windows.go +++ b/output_windows.go @@ -3,9 +3,8 @@ package prompt import ( - "io" - "context" + "io" "github.com/mattn/go-colorable" "github.com/mattn/go-tty" @@ -21,8 +20,7 @@ type WindowsWriter struct { // Flush to flush buffer func (w *WindowsWriter) Flush() error { - t := w.tty.Output() - _, err := t.Write(w.buffer) + _, err := w.writer.Write(w.buffer) if err != nil { return err } @@ -32,7 +30,7 @@ func (w *WindowsWriter) Flush() error { // GetWinSize returns WinSize object to represent width and height of terminal. func (w *WindowsWriter) GetWinSize() WinSize { - row, col, err := w.tty.Size() + col, row, err := w.tty.Size() if err != nil { panic(err) } @@ -61,12 +59,13 @@ var _ ConsoleWriter = &WindowsWriter{} // NewStandardOutputWriter returns ConsoleWriter object to write to stdout. // This generates win32 control sequences. func NewStandardOutputWriter() (ConsoleWriter, error) { - w := &WindowsWriter{} t, err := tty.Open() if err != nil { return nil, err } - w.tty = t - w.writer = colorable.NewColorable(t.Output()) + w := &WindowsWriter{ + tty: t, + writer: colorable.NewColorable(t.Output()), + } return w, nil } diff --git a/render.go b/render.go index 6bf9796..6b33b4d 100644 --- a/render.go +++ b/render.go @@ -322,6 +322,7 @@ func (r *Renderer) breakLine(buffer *Buffer) { r.out.WriteStr(buffer.Document().Text + "\n") r.out.SetColor(DefaultColor, DefaultColor, false) r.out.Flush() + r.previousCursor = 0 r.previousRequest.buffer = buffer }