Skip to content

Commit

Permalink
Handle linenoise (rdstdin) exception when forcing exit INim
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr. Green committed May 7, 2018
1 parent f1e8ad6 commit 64f9833
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion inim.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.2"
version = "0.2.3"
author = "Andrei Regiani"
description = "Interactive Nim Shell / REPL / Playground"
license = "MIT"
Expand Down
11 changes: 8 additions & 3 deletions src/inim.nim
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 64f9833

Please sign in to comment.