gilo/internal/terminal/raw.go

26 lines
386 B
Go
Raw Normal View History

2021-03-24 16:23:17 -04:00
package terminal
import (
"os"
"golang.org/x/term"
)
// Put the terminal in raw mode
func RawOn() *term.State {
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
return oldState
}
// Restore the terminal to canonical mode
func RawOff(oldState *term.State) {
err := term.Restore(int(os.Stdin.Fd()), oldState)
if err != nil {
panic(err)
}
}