From 82706223a4d6e04fc494dfc989dc45795b82c3f1 Mon Sep 17 00:00:00 2001 From: Andrei Regiani Date: Sat, 4 Aug 2018 17:04:46 +0200 Subject: [PATCH] 0.4.1: Windows fixes: removed unicode char from welcome screen, fixed nimble package warning, fixed Windows discard shortcut --- .gitignore | 4 ++-- inim.nimble | 2 +- src/inim.nim | 35 ++++++++++++++++++++++++---------- src/{ => inimpkg}/embedded.nim | 0 4 files changed, 28 insertions(+), 13 deletions(-) rename src/{ => inimpkg}/embedded.nim (100%) diff --git a/.gitignore b/.gitignore index 2b00a6e..4b006a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ nimcache/ -inim +src/inim +src/inim.exe inim_* -test temp.nim temp \ No newline at end of file diff --git a/inim.nimble b/inim.nimble index d3c08bb..f15e7ab 100644 --- a/inim.nimble +++ b/inim.nimble @@ -1,6 +1,6 @@ # Package -version = "0.4.0" +version = "0.4.1" author = "Andrei Regiani" description = "Interactive Nim Shell / REPL / Playground" license = "MIT" diff --git a/src/inim.nim b/src/inim.nim index 1ff7571..b6ea8f1 100644 --- a/src/inim.nim +++ b/src/inim.nim @@ -11,11 +11,11 @@ type App = ref object var app:App const - INimVersion = "0.4.0" + INimVersion = "0.4.1" indentSpaces = " " indentTriggers = [",", "=", ":", "var", "let", "const", "type", "import", "object", "enum"] # endsWith - embeddedCode = staticRead("embedded.nim") # preloaded code into user's session + embeddedCode = staticRead("inimpkg/embedded.nim") # preloaded code into user's session let uniquePrefix = epochTime().int @@ -53,7 +53,9 @@ proc getNimPath(): string = proc welcomeScreen() = stdout.setForegroundColor(fgYellow) - stdout.writeLine "👑 INim ", INimVersion + when defined(posix): + stdout.write "👑 " # Crashes on Windows: Unknown IO Error [IOError] + stdout.writeLine "INim ", INimVersion stdout.setForegroundColor(fgCyan) stdout.write getNimVersion() stdout.write getNimPath() @@ -67,6 +69,9 @@ proc cleanExit(exitCode = 0) = removeDir(getTempDir() & "nimcache") quit(exitCode) +proc controlCHook() {.noconv.} = + cleanExit(1) + proc getFileData(path: string): string = try: result = path.readFile() @@ -153,13 +158,22 @@ proc showError(output: string) = let message_seq = message.split(";") # expression;type, e.g 'a';char let typeExpression = message_seq[1] # type, e.g. char - let shortcut = fmt""" - stdout.write $({currentExpression}) - stdout.write "\e[33m" # Yellow - stdout.write " : " - stdout.write "{typeExpression}" - echo "\e[39m" # Reset color - """.replace(" ", "") + var shortcut:string + when defined(Windows): + shortcut = fmt""" + stdout.write $({currentExpression}) + stdout.write " : " + stdout.write "{typeExpression}" + echo "" + """.replace(" ", "") + else: # Posix: colorize type to yellow + shortcut = fmt""" + stdout.write $({currentExpression}) + stdout.write "\e[33m" # Yellow + stdout.write " : " + stdout.write "{typeExpression}" + echo "\e[39m" # Reset color + """.replace(" ", "") buffer.writeLine(shortcut) buffer.flushFile() @@ -183,6 +197,7 @@ proc showError(output: string) = previouslyIndented = false proc init(preload: string = nil) = + setControlCHook(controlCHook) bufferRestoreValidCode() if preload == nil: diff --git a/src/embedded.nim b/src/inimpkg/embedded.nim similarity index 100% rename from src/embedded.nim rename to src/inimpkg/embedded.nim