Skip to content

Commit 120dca2

Browse files
committed
.
1 parent e1aee77 commit 120dca2

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ class ReplDriver(settings: Array[String],
175175
s"""Welcome to Scala $simpleVersionString ($javaVersion, Java $javaVmName).
176176
|Type in expressions for evaluation. Or try :help.""".stripMargin)
177177

178-
// Track the time of last Ctrl-C
179-
var lastCtrlCTime: Long = 0L
180-
val ctrlCWindowMs = 1000L // 1 second window for double Ctrl-C
181-
182178
/** Blockingly read a line, getting back a parse result */
183179
def readLine()(using state: State): ParseResult = {
184180
given Context = state.context
@@ -223,27 +219,27 @@ class ReplDriver(settings: Array[String],
223219
}
224220

225221
@tailrec def loop(using state: State)(): State = {
222+
226223
val res = readLine()
227224
if (res == Quit) state
228-
else if (res == SigKill) {
229-
// Ctrl-C pressed at prompt - just continue with same state (line is cleared by JLine)
230-
loop(using state)()
231-
} else {
225+
// Ctrl-C pressed at prompt - just continue with same state (line is cleared by JLine)
226+
else if (res == SigKill) loop(using state)()
227+
else {
232228
// Set up interrupt handler for command execution
229+
var firstCtrlCEntered = false
233230
val thread = Thread.currentThread()
234231
val signalHandler = terminal.handle(
235232
org.jline.terminal.Terminal.Signal.INT,
236233
(sig: org.jline.terminal.Terminal.Signal) => {
237234
val now = System.currentTimeMillis()
238-
if (now - lastCtrlCTime < ctrlCWindowMs) {
239-
// Second Ctrl-C within window - interrupt the thread
240-
out.println("\nTerminating REPL...")
235+
if (!firstCtrlCEntered) {
236+
firstCtrlCEntered = true
241237
thread.interrupt()
238+
out.println("\nInterrupting running thread, Ctrl-C again to terminate the process")
239+
}else {
240+
out.println("\nTerminating REPL...")
241+
242242
System.exit(130) // Standard exit code for SIGINT
243-
} else {
244-
// First Ctrl-C - warn user
245-
lastCtrlCTime = now
246-
out.println("\nPress Ctrl-C again to terminate the process")
247243
}
248244
}
249245
)

0 commit comments

Comments
 (0)