bubbletea/tty.go

36 lines
469 B
Go
Raw Normal View History

2020-10-13 12:52:30 -04:00
package tea
import (
"github.com/containerd/console"
2020-10-13 12:52:30 -04:00
)
var tty console.Console
2020-10-13 12:52:30 -04:00
2021-01-11 16:33:14 -05:00
func (p Program) initTerminal() error {
if p.outputIsTTY {
tty = console.Current()
}
if p.inputIsTTY {
err := tty.SetRaw()
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 {
return nil
}
showCursor(p.output)
return tty.Reset()
2020-10-13 12:52:30 -04:00
}