From 8e21117986f128fb61ea2bcf3c366ea6a03d5f31 Mon Sep 17 00:00:00 2001 From: Sekulum Forka Date: Thu, 13 May 2021 22:40:06 +0200 Subject: [PATCH] Ctrl-C: Handles sigint much more elegantly --- src/fsh.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fsh.nim b/src/fsh.nim index 5ed6d17..bf45490 100644 --- a/src/fsh.nim +++ b/src/fsh.nim @@ -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: