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 ( ...@@ -8,6 +8,7 @@ import (
func errorCare(err error) { func errorCare(err error) {
if err != nil { if err != nil {
cliReset() cliReset()
termClose()
log.Fatal("An Error occured: ", err, "\n\nI am Sorry :(") log.Fatal("An Error occured: ", err, "\n\nI am Sorry :(")
} }
} }
...@@ -328,6 +328,7 @@ func logicUnknown(command string) { ...@@ -328,6 +328,7 @@ func logicUnknown(command string) {
// logicQuit exits the program // logicQuit exits the program
func logicQuit(none string) { func logicQuit(none string) {
cliReset() cliReset()
termClose()
os.Exit(0) os.Exit(0)
} }
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
var ( var (
termTerminal *terminal.Terminal termTerminal *terminal.Terminal
termRestore *terminal.State
) )
func init() { func init() {
...@@ -19,7 +20,8 @@ func init() { ...@@ -19,7 +20,8 @@ func init() {
os.Stdout, os.Stdout,
} }
_, err := terminal.MakeRaw(int(os.Stdin.Fd())) var err error
termRestore, err = terminal.MakeRaw(int(os.Stdin.Fd()))
errorCare(err) errorCare(err)
termTerminal = terminal.NewTerminal(stdio, "") termTerminal = terminal.NewTerminal(stdio, "")
...@@ -29,3 +31,10 @@ func init() { ...@@ -29,3 +31,10 @@ func init() {
func termReadLine() (string, error) { func termReadLine() (string, error) {
return termTerminal.ReadLine() return termTerminal.ReadLine()
} }
// termClose restores the terminal to its original state
func termClose() {
if termRestore != nil {
terminal.Restore(int(os.Stdin.Fd()), termRestore)
}
}
Supports Markdown
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