Ctrl-C: Handles sigint much more elegantly

This commit is contained in:
Sekulum Forka 2021-05-13 22:40:06 +02:00
parent 87982fdcbc
commit 8e21117986
1 changed files with 6 additions and 0 deletions

View File

@ -65,6 +65,10 @@ proc newShellCommandException(msg: string, command: string, line=0, col=0, while
proc eval(cmd: string): string
proc substitute(strm: Stream, delim = ";\p"): string
# ctrlc is the ctrl-c handler
proc ctrlc() {.noconv.} =
raise newException(InterruptCtrlC, "")
# skipSpaces reads the stream until a non-space character is found
proc skipSpaces(strm: Stream): int =
while not strm.atEnd():
@ -322,6 +326,8 @@ proc eval(cmd: string): string =
strm.close
when isMainModule:
# ctrlc handler
setControlCHook(ctrlc)
let stdinstrm = stdin.newFileStream
while not stdinstrm.atEnd():
try: