From 87982fdcbc48d2e1397812a7185cd608ec682103 Mon Sep 17 00:00:00 2001 From: Sekulum Forka Date: Thu, 13 May 2021 22:05:15 +0200 Subject: [PATCH] Exceptions: Add an exception for ^c --- src/fsh.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fsh.nim b/src/fsh.nim index 959e0a2..5ed6d17 100644 --- a/src/fsh.nim +++ b/src/fsh.nim @@ -35,6 +35,7 @@ type variable: string ShellCommandError = object of ShellError command: string + InterruptCtrlC = object of CatchableError # procs for making procedures proc newShellException(msg: string, line=0, col=0, whileExec=""): ref ShellError = @@ -323,4 +324,10 @@ proc eval(cmd: string): string = when isMainModule: let stdinstrm = stdin.newFileStream while not stdinstrm.atEnd(): - stdinstrm.readCommand.execute.echo + try: + discard stdinstrm.readCommand.execute + except ShellError, ShellCommandError, ShellVariableError: + let e = getCurrentException() + stderr.write(e.msg, "\n") + except InterruptCtrlC: + continue