Files
bubbletea/tty.go
Christian Rocha 9f9b3aea96 Read input regardless of whether or not it's a TTY
This commit also contains some refactors:

* Refactor away inputStatus type
* Refactor away program.inputIsTTY member
* Simplify how we setup and restore input when it's a TTY
2021-08-02 10:50:04 -04:00

48 lines
626 B
Go

package tea
import (
"errors"
)
var errInputIsNotAFile = errors.New("input is not a file")
func (p *Program) initTerminal() error {
err := p.initInput()
if err != nil {
return err
}
if p.console != nil {
err = p.console.SetRaw()
if err != nil {
return err
}
}
if p.outputIsTTY {
enableAnsiColors(p.output)
hideCursor(p.output)
}
return nil
}
func (p Program) restoreTerminal() error {
if p.outputIsTTY {
showCursor(p.output)
}
if p.console != nil {
err := p.console.Reset()
if err != nil {
return err
}
}
if err := p.restoreInput(); err != nil {
return err
}
return nil
}