Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make the Scala REPL not stop with CTRL-C

I'm using the Scala REPL to interactively test some hash functions I'm building. I'm constantly switching between the product code (Eclipse), the browser and the Scala interpreter, doing copy/paste of values and results. In the mix I'm often doing CTRL-C on the interpreter, exiting the session and loosing all my functions.

Is there any way to let the Scala REPL either ignore CTRL-C or, even better, perform "paste" with it? I'm working on Linux.

like image 968
maasg Avatar asked Sep 15 '11 17:09

maasg


People also ask

How do you stop an infinite loop in scala?

It depends on your scala version. If you are already on scala 2.9 it will work by just using CTRL-C. It might take some time untile the command reaches the REPL but it will abort your infinite loop at some time.

How do I leave scala REPL?

quit Command. Finally, we can close a REPL session via the :quit command or by pressing ctrl-D.

How do I get scala REPL from command prompt?

We can start Scala REPL by typing scala command in console/terminal.

What does the scala REPL stand for?

The Scala REPL (“Read-Evaluate-Print-Loop”) is a command-line interpreter that you use as a “playground” area to test your Scala code.


2 Answers

I only know how to prevent REPL from exiting. Remapping of CTRL+C to perform copy command could be done in the same way (if there is some command that ables to change keymap w/out restarting terminal -- I don't know is there one). Anyways, to block ^C wrap your REPL invocation in .sh script like this:

#!/bin/bash

#switch off sensitivity to ^C
trap '' 2

# here goes REPL invoke
scala

#get back sensitivity to ^C
trap 2

trap command

defines and activates handlers to be run when the shell receives signals or other conditions.

2 is a SIGINT value (that's the signal which is triggered when you press CTRL+C)

like image 139
om-nom-nom Avatar answered Sep 19 '22 18:09

om-nom-nom


The repl already intercepts ctrl-C, but apparently it doesn't work on linux. It does work on osx. If someone who uses linux opens a ticket with sufficient detail to indicate why not, I can fix it.

like image 35
psp Avatar answered Sep 21 '22 18:09

psp