forked from Mirrors/bubbletea
Use correct output when enabling ANSI colors on Windows (see #39)
This commit is contained in:
parent
c4aeadd762
commit
64da3bcf7a
2
tty.go
2
tty.go
|
@ -15,7 +15,7 @@ func initTerminal(w io.Writer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
enableAnsiColors()
|
enableAnsiColors(w)
|
||||||
hideCursor(w)
|
hideCursor(w)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package tea
|
package tea
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
// enableAnsiColors is only needed for Windows, so for other systems this is
|
// enableAnsiColors is only needed for Windows, so for other systems this is
|
||||||
// a no-op.
|
// a no-op.
|
||||||
func enableAnsiColors() {}
|
func enableAnsiColors(w io.Writer) {}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package tea
|
package tea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
@ -10,8 +11,13 @@ import (
|
||||||
|
|
||||||
// enableAnsiColors enables support for ANSI color sequences in Windows
|
// enableAnsiColors enables support for ANSI color sequences in Windows
|
||||||
// default console. Note that this only works with Windows 10.
|
// default console. Note that this only works with Windows 10.
|
||||||
func enableAnsiColors() {
|
func enableAnsiColors(w io.Writer) {
|
||||||
stdout := windows.Handle(os.Stdout.Fd())
|
f, ok := w.(*os.File)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout := windows.Handle(f.Fd())
|
||||||
var originalMode uint32
|
var originalMode uint32
|
||||||
|
|
||||||
windows.GetConsoleMode(stdout, &originalMode)
|
windows.GetConsoleMode(stdout, &originalMode)
|
||||||
|
|
Loading…
Reference in New Issue