Ctrl-C: Handles sigint much more elegantly
This commit is contained in:
parent
87982fdcbc
commit
8e21117986
|
@ -65,6 +65,10 @@ proc newShellCommandException(msg: string, command: string, line=0, col=0, while
|
||||||
proc eval(cmd: string): string
|
proc eval(cmd: string): string
|
||||||
proc substitute(strm: Stream, delim = ";\p"): 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
|
# skipSpaces reads the stream until a non-space character is found
|
||||||
proc skipSpaces(strm: Stream): int =
|
proc skipSpaces(strm: Stream): int =
|
||||||
while not strm.atEnd():
|
while not strm.atEnd():
|
||||||
|
@ -322,6 +326,8 @@ proc eval(cmd: string): string =
|
||||||
strm.close
|
strm.close
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
# ctrlc handler
|
||||||
|
setControlCHook(ctrlc)
|
||||||
let stdinstrm = stdin.newFileStream
|
let stdinstrm = stdin.newFileStream
|
||||||
while not stdinstrm.atEnd():
|
while not stdinstrm.atEnd():
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue