Fix windows writer
This commit is contained in:
parent
0f9b504036
commit
7f685d1a1d
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue