2017-08-16 03:22:38 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package prompt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/mattn/go-colorable"
|
|
|
|
)
|
|
|
|
|
2018-02-14 03:40:33 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-02-14 03:40:33 +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
|
|
|
|
2018-02-14 03:40:33 +00:00
|
|
|
// NewStandardOutputWriter returns ConsoleWriter object to write to stdout.
|
2018-06-20 16:31:29 +00:00
|
|
|
// This generates win32 control sequences.
|
2018-02-12 10:12:31 +00:00
|
|
|
func NewStandardOutputWriter() *WindowsWriter {
|
|
|
|
return &WindowsWriter{
|
2017-08-16 03:22:38 +00:00
|
|
|
out: colorable.NewColorableStdout(),
|
|
|
|
}
|
|
|
|
}
|