After aborting input, echo typing is disabled in the terminal
dpecos opened this issue · 3 comments
dpecos commented
- Operating System: Mac
- Terminal Emulator: iterm
- Bug behaviour: with line.SetCtrlCAborts(true), after pressing Ctrl+C during input, terminal does not echo typing anymore
- Expected behaviour: after exiting the application, command line should behave as before.
peterh commented
Did you forget to call line.Close() before exiting? This behaviour should be the same regardless of whether "SetCtrlCAborts" is set or not.
dpecos commented
I already have something like this:
line := liner.NewLiner()
defer line.Close()
line.SetCtrlCAborts(true)
But looks like is not good enough :( . Here you can find the method I'm using it, just in case you would like to have a futher look: https://github.com/dpecos/cmdbox/blob/master/tools/console.go
Thanks!
dpecos commented
Ok, I managed to solve my issue: I was deferring line.Close() but I also was executing log.Fatal() within the error handling for line.Prompt, so line.Close() was not being invoked. Using this kind of error handling solved the problem:
text, err := line.Prompt(label)
if err != nil {
if err == liner.ErrPromptAborted {
line.Close()
os.Exit(0)
} else {
log.Fatal(err)
}
}
Thx a lot!