forked from c-bata/go-prompt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
writer_windows.go
50 lines (41 loc) · 1.02 KB
/
writer_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build windows
// +build windows
package prompt
import (
"io"
colorable "github.com/mattn/go-colorable"
)
// WindowsWriter is a Writer implementation for Win32 console.
// Output is converted from VT100 escape sequences by mattn/go-colorable.
type WindowsWriter struct {
VT100Writer
out io.Writer
}
// Flush to flush buffer
func (w *WindowsWriter) Flush() error {
_, err := w.out.Write(w.buffer)
if err != nil {
return err
}
w.buffer = []byte{}
return nil
}
var _ Writer = &WindowsWriter{}
var (
// NewStandardOutputWriter is Deprecated: Please use NewStdoutWriter
NewStandardOutputWriter = NewStdoutWriter
)
// NewStdoutWriter returns Writer object to write to stdout.
// This generates win32 control sequences.
func NewStdoutWriter() Writer {
return &WindowsWriter{
out: colorable.NewColorableStdout(),
}
}
// NewStderrWriter returns Writer object to write to stderr.
// This generates win32 control sequences.
func NewStderrWriter() Writer {
return &WindowsWriter{
out: colorable.NewColorableStderr(),
}
}