@@ -159,10 +159,6 @@ class ReplDriver(settings: Array[String],
159159 s """ Welcome to Scala $simpleVersionString ( $javaVersion, Java $javaVmName).
160160 |Type in expressions for evaluation. Or try :help. """ .stripMargin)
161161
162- // Track the time of last Ctrl-C
163- var lastCtrlCTime : Long = 0L
164- val ctrlCWindowMs = 1000L // 1 second window for double Ctrl-C
165-
166162 /** Blockingly read a line, getting back a parse result */
167163 def readLine ()(using state : State ): ParseResult = {
168164 given Context = state.context
@@ -207,27 +203,27 @@ class ReplDriver(settings: Array[String],
207203 }
208204
209205 @ tailrec def loop (using state : State )(): State = {
206+
210207 val res = readLine()
211208 if (res == Quit ) state
212- else if (res == SigKill ) {
213- // Ctrl-C pressed at prompt - just continue with same state (line is cleared by JLine)
214- loop(using state)()
215- } else {
209+ // Ctrl-C pressed at prompt - just continue with same state (line is cleared by JLine)
210+ else if (res == SigKill ) loop(using state)()
211+ else {
216212 // Set up interrupt handler for command execution
213+ var firstCtrlCEntered = false
217214 val thread = Thread .currentThread()
218215 val signalHandler = terminal.handle(
219216 org.jline.terminal.Terminal .Signal .INT ,
220217 (sig : org.jline.terminal.Terminal .Signal ) => {
221218 val now = System .currentTimeMillis()
222- if (now - lastCtrlCTime < ctrlCWindowMs) {
223- // Second Ctrl-C within window - interrupt the thread
224- out.println(" \n Terminating REPL..." )
219+ if (! firstCtrlCEntered) {
220+ firstCtrlCEntered = true
225221 thread.interrupt()
222+ out.println(" \n Interrupting running thread, Ctrl-C again to terminate the process" )
223+ }else {
224+ out.println(" \n Terminating REPL..." )
225+
226226 System .exit(130 ) // Standard exit code for SIGINT
227- } else {
228- // First Ctrl-C - warn user
229- lastCtrlCTime = now
230- out.println(" \n Press Ctrl-C again to terminate the process" )
231227 }
232228 }
233229 )
0 commit comments