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

Ctrl+C quits repl (SIGINT signal) #180

Open
dundalek opened this issue Sep 29, 2018 · 4 comments
Open

Ctrl+C quits repl (SIGINT signal) #180

dundalek opened this issue Sep 29, 2018 · 4 comments

Comments

@dundalek
Copy link

When a longer running form is evaluated (e.g. (Thread/sleep 10000) or (doseq [i (range 1e6)] (println i))) and Ctrl+C is pressed then repl quits. Expected behavior is to interrupt current evaluation and make the repl available for input again.

Version used: 0.1.4 (running with clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.4\"}}}" -m rebel-readline.main).

For comparison I tried clj main repl which also handles it incorrectly, but lein repl handles it correctly as expected.

@bhauman
Copy link
Owner

bhauman commented Sep 29, 2018 via email

@dundalek
Copy link
Author

dundalek commented Sep 29, 2018

Sounds cool to me, thank you so much for your OSS work. Not only for this project but also the other ones! Huge respect!

I am working on a unix shell project based on Clojure and am able to have so much leverage thanks to rebel. If rebel would not exist I would not even consider Java proper port. It is almost complete, the last thing it needs is above mentioned ctrl+c handling, otherwise a bash-like shell is sort of useless.

I've now quickly looked into lein, which seems to hook into java signal handling. Another option might be to use jline3 apis, which seem to have some sort of native signal handling.

I think the solution should be able to be made upstream. So if I am able to come up with something PR-worthy I will open one up for your consideration.

@dundalek
Copy link
Author

Hi Bruce,

I did more digging into how lein and reply do things and was able to come up with a solution:

(defn handle-sigint-form []
  `(let [thread# (Thread/currentThread)]
     (clojure.repl/set-break-handler! (fn [signal#] (.stop thread#)))))

Then can pass following eval option to clojure.main/repl:

  :eval (fn [form] (eval `(do ~(handle-sigint-form) ~form)))

I hope this helps. I am able to customize rebel like that so it is solved for my project.

christoph-frick added a commit to christoph-frick/clj-wrepl that referenced this issue Nov 15, 2018
@metametadata
Copy link

I've wrapped up the aforementioned workaround into the script: https://gist.github.com/metametadata/c11044a5d490eac7158ae535c10ce45c.

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

3 participants