Fix windows writer

This commit is contained in:
c-bata 2018-06-28 22:11:35 +09:00
parent 0f9b504036
commit 7f685d1a1d
4 changed files with 12 additions and 16 deletions

View File

@ -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
}
}
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}