mirror of
https://github.com/apple/pkl.git
synced 2026-04-24 01:08:34 +02:00
Improve interrupt handling in pkl repl (#1188)
This commit is contained in:
@@ -52,6 +52,7 @@ internal class Repl(workingDir: Path, private val server: ReplServer) {
|
|||||||
|
|
||||||
private var continuation = false
|
private var continuation = false
|
||||||
private var quit = false
|
private var quit = false
|
||||||
|
private var maybeQuit = false
|
||||||
private var nextRequestId = 0
|
private var nextRequestId = 0
|
||||||
|
|
||||||
fun run() {
|
fun run() {
|
||||||
@@ -74,11 +75,23 @@ internal class Repl(workingDir: Path, private val server: ReplServer) {
|
|||||||
reader.readLine("pkl$nextRequestId> ")
|
reader.readLine("pkl$nextRequestId> ")
|
||||||
}
|
}
|
||||||
} catch (e: UserInterruptException) {
|
} catch (e: UserInterruptException) {
|
||||||
":quit"
|
if (!continuation && reader.buffer.length() == 0) {
|
||||||
|
if (maybeQuit) quit()
|
||||||
|
else {
|
||||||
|
maybeQuit = true
|
||||||
|
println("(To exit, press ^C again or ^D or type :quit)")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maybeQuit = false
|
||||||
|
}
|
||||||
|
inputBuffer = ""
|
||||||
|
continuation = false
|
||||||
|
continue
|
||||||
} catch (e: EndOfFileException) {
|
} catch (e: EndOfFileException) {
|
||||||
":quit"
|
":quit"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybeQuit = false
|
||||||
val input = line.trim()
|
val input = line.trim()
|
||||||
if (input.isEmpty()) continue
|
if (input.isEmpty()) continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user