bubbletea/tty.go

28 lines
472 B
Go
Raw Normal View History

2020-10-13 12:52:30 -04:00
package tea
import (
"os"
"github.com/muesli/termenv"
"golang.org/x/crypto/ssh/terminal"
)
var origTTYState *terminal.State
func initTerminal() error {
var err error
origTTYState, err = terminal.MakeRaw(int(os.Stdin.Fd())) // enter raw mode
if err != nil {
return err
}
enableAnsiColors()
termenv.HideCursor()
return nil
}
func restoreTerminal() error {
termenv.ShowCursor()
return terminal.Restore(int(os.Stdin.Fd()), origTTYState) // exit raw mode
}