gilo/terminal/raw.go
Timothy J. Warren e7ba61b2aa
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
Add more tests
2021-03-31 19:17:04 -04:00

26 lines
386 B
Go

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)
}
}