From 64f98335e1b3fb89a14d858df0977601205c21b0 Mon Sep 17 00:00:00 2001 From: "Mr. Green" Date: Mon, 7 May 2018 15:11:21 +0200 Subject: [PATCH] Handle linenoise (rdstdin) exception when forcing exit INim --- inim.nimble | 2 +- src/inim.nim | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/inim.nimble b/inim.nimble index 2fc6529..d6ddb6c 100644 --- a/inim.nimble +++ b/inim.nimble @@ -1,6 +1,6 @@ # Package -version = "0.2.2" +version = "0.2.3" author = "Andrei Regiani" description = "Interactive Nim Shell / REPL / Playground" license = "MIT" diff --git a/src/inim.nim b/src/inim.nim index e129fc7..c198804 100644 --- a/src/inim.nim +++ b/src/inim.nim @@ -1,7 +1,7 @@ import os, osproc, rdstdin, strutils, terminal, times const - INimVersion = "0.2.2" + INimVersion = "0.2.3" indentationTriggers = ["=", ":", "var", "let", "const", "import"] # endsWith indentationSpaces = " " bufferDefaultImports = "import typetraits" # @TODO: shortcut to display type and value @@ -103,13 +103,18 @@ proc hasIndentationTrigger*(line: string): bool = proc runForever() = while true: - let myline = readLineFromStdin(getPromptSymbol()).strip + # Read line + var myline: string + try: + myline = readLineFromStdin(getPromptSymbol()).strip + except IOError: + return # Special commands if myline in ["exit", "quit()"]: cleanExit() - # Empty line: leave indentation level otherwise do nothing + # Empty line: exit indentation level, otherwise do nothing if myline == "": if indentationLevel > 0: indentationLevel -= 1