Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala ctrl c not leave REPL

I comes from Python background and just begin to use scala.

In python shell, when I type in a command and find a typo in it, I usually use ctrl c to generate a keyboard Interrupt exception so that I can directly type the next statement. The previous statement won't be executed, and I'm still in Python shell.

But in Scala REPL, when I enter ctrl c, I'll immediately quit the Scala REP, which is annoying to me.

Is there anyway to make REPL works like python shell?

Scala version I'm using is 2.11.7. I'm using Mac.

like image 213
xuanyue Avatar asked Oct 28 '15 18:10

xuanyue


People also ask

How do I exit a program in scala?

Exit(0); import 'dart:io'; exit(0);

How do you get to scala REPL?

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


2 Answers

You could try Ammonite-REPL by Li Haoyi. Among many other improvements, it does capture Ctrl+C.

like image 183
Rüdiger Klaehn Avatar answered Oct 07 '22 21:10

Rüdiger Klaehn


I don't think Ctrl+C is even the right way to use Python REPL to abandon a mistyped command, there are several shortcuts probably will make your life easier here.

Ctrl+U should be the command you are looking for.

Erases the complete line.

Basically Ctrl+U will delete anything before the cursor, which should abandon the existing line completely if you are typing.
If your cursor is in the middle, you can use Ctrl+E to go the end first, and then Ctrl+U.

I tested in the shell, Python REPL and Scala REPL and they all work. For the curious minds:

  • Ctrl+A will go to the beginning,
  • Ctrl+K will delete the text after the cursor.
like image 21
B.Mr.W. Avatar answered Oct 07 '22 22:10

B.Mr.W.