check for valid terminal
This commit is contained in:
parent
64b7a51f69
commit
eb474ddad2
@ -2,12 +2,22 @@ package terminal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/term"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Is this a valid interactive terminal?
|
||||||
|
func check() {
|
||||||
|
if !term.IsTerminal(int(os.Stdin.Fd())) {
|
||||||
|
panic("An interactive terminal is required to use a text editor!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Put the terminal in raw mode
|
// Put the terminal in raw mode
|
||||||
func RawOn() *term.State {
|
func RawOn() *term.State {
|
||||||
|
check()
|
||||||
|
|
||||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user