2020-01-25 01:15:29 -05:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
|
|
|
|
package tea
|
|
|
|
|
|
|
|
import (
|
2020-01-31 07:47:36 -05:00
|
|
|
"github.com/muesli/termenv"
|
2020-01-25 01:15:29 -05:00
|
|
|
"github.com/pkg/term"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
tty *term.Term
|
|
|
|
)
|
|
|
|
|
|
|
|
func initTerminal() error {
|
|
|
|
var err error
|
|
|
|
tty, err = term.Open("/dev/tty")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-17 14:35:54 -04:00
|
|
|
err = tty.SetRaw()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-01-31 07:47:36 -05:00
|
|
|
termenv.HideCursor()
|
2020-01-25 01:15:29 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func restoreTerminal() {
|
2020-01-31 07:47:36 -05:00
|
|
|
termenv.ShowCursor()
|
2020-04-17 14:35:54 -04:00
|
|
|
_ = tty.Restore()
|
2020-01-25 01:15:29 -05:00
|
|
|
}
|