2020-10-13 12:52:30 -04:00
|
|
|
package tea
|
|
|
|
|
|
|
|
import (
|
2020-12-03 10:18:58 -05:00
|
|
|
"io"
|
|
|
|
|
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
|
|
|
|
2020-12-03 10:18:58 -05:00
|
|
|
func initTerminal(w io.Writer) error {
|
2020-10-13 14:41:35 -04:00
|
|
|
tty = console.Current()
|
|
|
|
err := tty.SetRaw()
|
2020-10-13 12:52:30 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
enableAnsiColors()
|
2020-12-03 10:18:58 -05:00
|
|
|
hideCursor(w)
|
2020-10-13 12:52:30 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-03 10:18:58 -05:00
|
|
|
func restoreTerminal(w io.Writer) error {
|
|
|
|
showCursor(w)
|
2020-10-13 14:41:35 -04:00
|
|
|
return tty.Reset()
|
2020-10-13 12:52:30 -04:00
|
|
|
}
|