Open ageron opened 4 months ago
Thanks for the thorough investigation of what other repls do here!
So it's actually bothered me that in other repls Ctrl-C doesn't exit, especially because if I end up in the repl by mistake, Ctrl-C is my go-to "I don't know how to exit this program but this is the key combination that exits programs" button. It's both standard and frustrating to me, and the standardization of that frustration makes it even worse. π
What if we made Ctrl-C cancel the current command if you have something entered, but if you're at a blank prompt (e.g. you press Ctrl-C twice in a row), then it exits?
I've definitely used other programs where pressing Ctrl-C twice is necessary to exit the program, which feels both okay here and also something I would naturally try if I were trying to exit the program (namely, pressing Ctrl-C more than once).
Hi Richard, thanks for your reply. Your suggestion would definitely be a great improvement over the current situation. π And I like the spirit of questioning the status quo when it's a bad status quo. But in this case I think it's a good status quo. There are good reasons why it has become the de facto standard:
I believe this is why shells all adopted a different keystroke to exit (Ctrl-D = EOF). I sometimes have valuable data in a shell, and exiting by mistake is a really painful experience.
That said, I remember being frustrated the first few times I used shells (a few decades ago), because I didn't know how to exit (not the same level of frustration as trying to exit vi, but still not negligible). A simple solution would be to print "Please press Ctrl-D to exit the REPL" if you press Ctrl-C on an empty command.
Also note that bash (and other shells) let you change the default behavior if you want: you can tell it to exit on Ctrl-C if you really want to (trap "exit" INT
). We could imagine offering the same option in ROC's REPL (but you might be one of the only users of that option, haha π).
Mmh, it looks like rustyline just returns an Err(ReadlineError::Interrupted)
when you press Ctrl-C, there's no way to know whether or not the line was empty or not. So if we display a message, it would appear every time, whether the command is empty or not.
I for one vote for no message at all. As I mentioned earlier, the REPL starts with a message that explains how to exit, so no need to repeat it, IMHO.
but you might be one of the only users of that option, haha
I'd use it :)
I'm just like @rtfeldman, I always get annoyed at REPLs that don't βC. I guess the logic for βD makes sense, but I'm still with @rtfeldman. I guess the message at the top is fine, as I usually want to exit when I accidentally enter. (i.e., if the plain roc
command entered a repl instead of help, which is honestly what I expect from a language given all of the above REPLs' behavior, though I prefer a help message).
Anyway, I'd go with "fine, change it." You're right, but I'm still saddened to lose βC.
Have a nice day.
I also like the idea proposed by Richard and think we should aim for that behaviour if possible.
I don't have a lot of experience with other REPLs, so I like that it is easy to exit the program using ^C, but I guess I didn't know about ^D.
I'm new to ROC, really enjoying it so far. π
However, in ROC's REPL, pressing Ctrl-C shuts down the REPL immediately (at least on MacOS). I lose whatever I was doing.
In pretty much every other REPL I've ever used, Ctrl-C just cancels the command I'm typing (or only interrupts the currently running evaluation). I've tested the following REPLs:
^C
at the end of the command)^C
)KeyboardInterrupt
)ROC's REPL should not shutdown when Ctrl-C is pressed. It should have the "standard" behavior instead, which prevents losing a session by mistake, and makes it more convenient to cancel the current command (in ROC's REPL, you can type Ctrl-A followed by Ctrl-K, but it's neither obvious nor convenient).
If you're okay with that, I'm happy to contribute a fix (but it might take me a while, I just started learning ROC).
Edit: actually, it might be a really simple fix: removing line 96 (
return 1
) in crates/repl_cli/src/lib.rs