diff --git a/tty.go b/tty.go index 25f2415..6e50141 100644 --- a/tty.go +++ b/tty.go @@ -15,7 +15,7 @@ func initTerminal(w io.Writer) error { return err } - enableAnsiColors() + enableAnsiColors(w) hideCursor(w) return nil } diff --git a/tty_unix.go b/tty_unix.go index f71efeb..c2b0015 100644 --- a/tty_unix.go +++ b/tty_unix.go @@ -2,6 +2,8 @@ package tea +import "io" + // enableAnsiColors is only needed for Windows, so for other systems this is // a no-op. -func enableAnsiColors() {} +func enableAnsiColors(w io.Writer) {} diff --git a/tty_windows.go b/tty_windows.go index b9ddd4b..cfb0351 100644 --- a/tty_windows.go +++ b/tty_windows.go @@ -3,6 +3,7 @@ package tea import ( + "io" "os" "golang.org/x/sys/windows" @@ -10,8 +11,13 @@ import ( // enableAnsiColors enables support for ANSI color sequences in Windows // default console. Note that this only works with Windows 10. -func enableAnsiColors() { - stdout := windows.Handle(os.Stdout.Fd()) +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)