bubbletea/tty.go

48 lines
626 B
Go
Raw Normal View History

2020-10-13 12:52:30 -04:00
package tea
import (
"errors"
2020-10-13 12:52:30 -04:00
)
var errInputIsNotAFile = errors.New("input is not a file")
2020-10-13 12:52:30 -04:00
func (p *Program) initTerminal() error {
err := p.initInput()
if err != nil {
return err
2021-01-11 16:33:14 -05:00
}
if p.console != nil {
err = p.console.SetRaw()
2021-01-11 16:33:14 -05:00
if err != nil {
return err
}
}
if p.outputIsTTY {
enableAnsiColors(p.output)
hideCursor(p.output)
2020-10-13 12:52:30 -04:00
}
return nil
}
2021-01-11 16:33:14 -05:00
func (p Program) restoreTerminal() error {
if p.outputIsTTY {
showCursor(p.output)
}
if p.console != nil {
err := p.console.Reset()
if err != nil {
return err
}
2021-01-11 16:33:14 -05:00
}
if err := p.restoreInput(); err != nil {
return err
}
return nil
2020-10-13 12:52:30 -04:00
}