Fix Windows stuff related to the refactor at 49a5d16

This commit is contained in:
Christian Rocha
2021-07-29 17:59:36 -04:00
parent 67625b480e
commit 5f41a91e02
3 changed files with 7 additions and 23 deletions

3
tea.go
View File

@@ -371,9 +371,8 @@ func (p *Program) Start() error {
}() }()
} }
// Is output a terminal?
if f, ok := p.output.(*os.File); ok { if f, ok := p.output.(*os.File); ok {
// Get initial terminal size // Get initial terminal size and send it to the program
go func() { go func() {
w, h, err := term.GetSize(int(f.Fd())) w, h, err := term.GetSize(int(f.Fd()))
if err != nil { if err != nil {

6
tty.go
View File

@@ -1,11 +1,5 @@
package tea package tea
import (
"errors"
)
var errInputIsNotAFile = errors.New("input is not a file")
func (p *Program) initTerminal() error { func (p *Program) initTerminal() error {
err := p.initInput() err := p.initInput()
if err != nil { if err != nil {

View File

@@ -11,28 +11,19 @@ import (
) )
func (p *Program) initInput() error { func (p *Program) initInput() error {
if !p.inputIsTTY { // If input's a file, use console to manage it
return nil if f, ok := p.input.(*os.File); ok {
}
// If input's a TTY this should always succeed.
f, ok := p.input.(*os.File)
if !ok {
return errInputIsNotAFile
}
if p.inputStatus == managedInput {
// Save a reference to the current stdin then replace stdin with our // Save a reference to the current stdin then replace stdin with our
// input. We do this so we can hand input off to containerd/console to // input. We do this so we can hand input off to containerd/console to
// set raw mode, and do it in this fashion because the method // set raw mode, and do it in this fashion because the method
// console.ConsoleFromFile isn't supported on Windows. // console.ConsoleFromFile isn't supported on Windows.
p.windowsStdin = os.Stdin p.windowsStdin = os.Stdin
os.Stdin = f os.Stdin = f
}
// Note: this will panic if it fails. // Note: this will panic if it fails.
c := console.Current() c := console.Current()
p.console = c p.console = c
}
enableAnsiColors(p.output) enableAnsiColors(p.output)