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

Feature: Using ctrl-C #33

Open
jwoertink opened this issue Nov 15, 2016 · 5 comments
Open

Feature: Using ctrl-C #33

jwoertink opened this issue Nov 15, 2016 · 5 comments

Comments

@jwoertink
Copy link
Collaborator

jwoertink commented Nov 15, 2016

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.

@greyblake
Copy link
Member

The idea sounds awesome! Is your proposal to work on that still relevant, if so, I (and I believe community) would really appreciate that!

@jwoertink
Copy link
Collaborator Author

jwoertink commented Jan 31, 2017 via email

@greyblake
Copy link
Member

Sounds good! Thanks again for your support and initiative!

@bew
Copy link

bew commented Mar 17, 2018

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

@jwoertink
Copy link
Collaborator Author

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants