feat: use Termenv.Output to write to tty

This commit is contained in:
Christian Muehlhaeuser
2022-06-04 15:14:03 +02:00
parent 5c4218e5f6
commit 6c449e55bf
13 changed files with 111 additions and 219 deletions

View File

@@ -4,11 +4,9 @@
package tea
import (
"io"
"os"
"github.com/containerd/console"
"golang.org/x/sys/windows"
)
func (p *Program) initInput() error {
@@ -26,8 +24,6 @@ func (p *Program) initInput() error {
p.console = c
}
enableAnsiColors(p.output)
return nil
}
@@ -49,18 +45,3 @@ func openInputTTY() (*os.File, error) {
}
return f, nil
}
// enableAnsiColors enables support for ANSI color sequences in Windows
// default console. Note that this only works with Windows 10.
func enableAnsiColors(w io.Writer) {
f, ok := w.(*os.File)
if !ok {
return
}
stdout := windows.Handle(f.Fd())
var originalMode uint32
_ = windows.GetConsoleMode(stdout, &originalMode)
_ = windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}