peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.04k stars 132 forks source link

After aborting input, echo typing is disabled in the terminal #104

Closed dpecos closed 6 years ago

dpecos commented 6 years ago
peterh commented 6 years ago

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 6 years ago

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 6 years ago

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!