Commit b624af94 authored by Jonny Schäfer's avatar Jonny Schäfer
Browse files

add termClose to restore the terminal state

parent c576c707
......@@ -8,6 +8,7 @@ import (
func errorCare(err error) {
if err != nil {
cliReset()
termClose()
log.Fatal("An Error occured: ", err, "\n\nI am Sorry :(")
}
}
......@@ -328,6 +328,7 @@ func logicUnknown(command string) {
// logicQuit exits the program
func logicQuit(none string) {
cliReset()
termClose()
os.Exit(0)
}
......
......@@ -8,6 +8,7 @@ import (
var (
termTerminal *terminal.Terminal
termRestore *terminal.State
)
func init() {
......@@ -19,7 +20,8 @@ func init() {
os.Stdout,
}
_, err := terminal.MakeRaw(int(os.Stdin.Fd()))
var err error
termRestore, err = terminal.MakeRaw(int(os.Stdin.Fd()))
errorCare(err)
termTerminal = terminal.NewTerminal(stdio, "")
......@@ -29,3 +31,10 @@ func init() {
func termReadLine() (string, error) {
return termTerminal.ReadLine()
}
// termClose restores the terminal to its original state
func termClose() {
if termRestore != nil {
terminal.Restore(int(os.Stdin.Fd()), termRestore)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment