icr
icr copied to clipboard
Feature: Using ctrl-C
When using IRB
, if you're writing out multi-line code, and you make a typo, you can use ctrl-C
to sort of reset you back to normal. Take this for example:
[14:07PM] crystal-icr (bugs/alias)$ irb
2.3.1 :001 > class Dog
2.3.1 :002?> def bark
2.3.1 :003?> ebd
2.3.1 :004?> ^C
2.3.1 :004 > 1 + 1
=> 2
2.3.1 :005 > puts "back to normal"
back to normal
=> nil
With ICR currently, if you hit ctrl-C
, then it will completely exits the session back to your main prompt. If you've been spending time building out an example, then you will have lost setting up variables and such.
Since this needs to work a bit different than how IRB works, my plan would be to create some sort of status that knows if the current state is ok or not. Then catching Signal::INT
would basically clear everything back to the last good state.
If you like the idea, then I'll work on sending a PR.
The idea sounds awesome! Is your proposal to work on that still relevant, if so, I (and I believe community) would really appreciate that!
Yup! I just didn't want to put in a bunch of effort and then get it rejected (has happened before to me) 😅
I'll start working on it and then submit a WIP PR so you can follow along and maybe help with some suggestions along the way. Thanks!
~Jeremy
On Jan 31, 2017, at 3:46 AM, Sergey Potapov [email protected] wrote:
The idea sounds awesome! Is your proposal to work on that still relevant, if so, I (and I believe community) would really appreciate that!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Sounds good! Thanks again for your support and initiative!
Maybe something like this would work? https://stackoverflow.com/a/41917863/5655255 (warning C code)
void int_handler(int status)
{
printf("\n"); // Move to a new line
rl_on_new_line(); // Regenerate the prompt on a newline
rl_replace_line("", 0); // Clear the previous text
rl_redisplay();
}
We'd just need to bind rl_on_new_line
, rl_replace_line
and rl_redisplay
Possibly. I will need to look back in to it. I had been waiting for this thing to get fixed before I attempted this again, but maybe it's fixed now? Thanks for the suggestion @bew 👍