2020-10-13 12:52:30 -04:00
|
|
|
package tea
|
|
|
|
|
|
|
|
import (
|
2020-10-13 14:41:35 -04:00
|
|
|
"github.com/containerd/console"
|
2020-10-13 12:52:30 -04:00
|
|
|
)
|
|
|
|
|
2020-10-13 14:41:35 -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)
|
2020-10-13 14:41:35 -04:00
|
|
|
return tty.Reset()
|
2020-10-13 12:52:30 -04:00
|
|
|
}
|