go-prompt/output_windows.go

37 lines
731 B
Go
Raw Normal View History

2017-08-16 03:22:38 +00:00
// +build windows
package prompt
import (
"io"
"github.com/mattn/go-colorable"
)
// WindowsWriter is a ConsoleWriter implementation for Win32 console.
// Output is converted from VT100 escape sequences by mattn/go-colorable.
2018-02-12 10:12:31 +00:00
type WindowsWriter struct {
2018-06-20 16:31:29 +00:00
VT100Writer
out io.Writer
2017-08-16 03:22:38 +00:00
}
// Flush to flush buffer
2018-02-12 10:12:31 +00:00
func (w *WindowsWriter) Flush() error {
2017-08-16 03:22:38 +00:00
_, err := w.out.Write(w.buffer)
if err != nil {
return err
}
w.buffer = []byte{}
return nil
}
2018-02-12 10:12:31 +00:00
var _ ConsoleWriter = &WindowsWriter{}
2017-08-16 03:22:38 +00:00
// NewStandardOutputWriter returns ConsoleWriter object to write to stdout.
2018-06-20 16:31:29 +00:00
// This generates win32 control sequences.
2018-10-20 04:06:36 +00:00
func NewStandardOutputWriter() ConsoleWriter {
2018-02-12 10:12:31 +00:00
return &WindowsWriter{
2017-08-16 03:22:38 +00:00
out: colorable.NewColorableStdout(),
}
}