26 lines
386 B
Go
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)
|
|
}
|
|
}
|