Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up when the app exits #91

Closed
jcw opened this issue Oct 21, 2016 · 1 comment
Closed

Cleaning up when the app exits #91

jcw opened this issue Oct 21, 2016 · 1 comment

Comments

@jcw
Copy link

jcw commented Oct 21, 2016

Hello - I'm having a hard time figuring out how to cleanly restore the tty state to cooked mode when my application exits. I can use a defer.Close() in the goroutine where rl.ReadLine() is running, but the problem is that sometimes my application must quit programmatically (or panics). In these cases, the program exists and leaves the terminal in a very confusing raw/noecho mode.

The only workaround I can think of is to open a pipe to a child process, which then waits for its input to close before it runs stty sane (but this won't be portable to Windows, as far as I know). And it feels like a hack...

Is there a standard idiom for this? Or some example code, perhaps?

@chzyer
Copy link
Owner

chzyer commented Oct 23, 2016

hi, it seems there has no ways to restore the tty state if it's exit unexpected.
And I can't see any terminal applications support this, even vim if I send kill -9 to it.
So, the only way is you keeping defer recover() it your every goroutines, make sure it exit properly.

@chzyer chzyer closed this as completed Oct 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants