withoutboats / notty

A new kind of terminal
GNU Affero General Public License v3.0
2.3k stars 41 forks source link

Fail slightly more gracefully on Ctrl-D #31

Closed pscollins closed 8 years ago

pscollins commented 8 years ago

This is intended as a temporary fix to the "can't quit without Ctrl-C in the original terminal" problem. A more complete solution probably catches EOF in the parser and starts the shutdown there, but this works apart from the misleading error message.

withoutboats commented 8 years ago

Thanks for the PR!

We actually don't want to exit when we parse Ctrl-C or Ctrl-D, and this is closer to the complete solution that you think.

Ctrl-C and Ctrl-D both kill the shell because of settings in the kernel's tty subsystem and features of the shell. In brief, Ctrl-C is set to send the shell SIGINT, which most shells respond to by exiting. Ctrl-D is set to cause reading from stdin to return EOF, which most shells respond to by exiting. Both the association between these characters and these events and the response to these events are determined outside of our domain, in the tty and the shell respectively. Shells can also be caused to exit in any number of other undetectable ways, such as calling kill on the shell's process from another shell running in another tty.

As a result, all we want to do is exit when reading from or writing to the tty fails, and nothing 'smarter' than that. The only thing this is missing is catching IO errors that could result form writing to a dead tty, which is the error that could result from cmd.apply which is in another part of the same file.

withoutboats commented 8 years ago

I merged this change in and also added a call when the cmd gets applied. I modified to from the match statement to the terser unwrap_or_else(exit_on_io_error) form.

withoutboats commented 8 years ago

On my machine, it doesn't exit until I type again after Ctrl+D, is that true for you as well?

pscollins commented 8 years ago

@withoutboats Nifty to know that, thanks. I don't know much Rust but I'd like an excuse to learn some. I made a very, very incomplete terminal emulator in Haskell a while back which I've been half-heartedly trying to rewrite in Perl for a while. I like to mess around with terminal emulators, anyway, and I plan to poke some more at this project when I have some time.

My local copy exits immediately on Ctrl-D with the message:

➜  scaffolding git:(exit-dont-panic) ✗ cargo run
     Running `target/debug/scaffolding-terminal`
Quitting because: Input/output error (os error 5)
Process didn't exit successfully: `target/debug/scaffolding-terminal` (exit code: 1)

but again, things tend to behave strangely for me because of xmonad.