From f1e8ad6b1826401e0a1bd615324159a12a8c95de Mon Sep 17 00:00:00 2001 From: Andrei Regiani Date: Sat, 5 May 2018 00:13:59 +0200 Subject: [PATCH] * Colorized output (red for errors, cyan for results) --- README.md | 1 + src/inim.nim | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 56ee22c..a51086b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ * Uses current `nim` compiler in PATH * Runs in the current directory: `import` your local modules (access to exported* symbols) * Preload existing source code (access to non-exported* symbols): `inim example.nim` +* Colorized output (red for errors, cyan for results) ## Contributing Pull requests and suggestions are welcome. diff --git a/src/inim.nim b/src/inim.nim index 8064bc2..e129fc7 100644 --- a/src/inim.nim +++ b/src/inim.nim @@ -35,9 +35,12 @@ proc getNimPath(): string = return "\n" proc welcomeScreen() = + stdout.setForegroundColor(fgCyan) stdout.writeLine "INim ", INimVersion stdout.write getNimVersion() stdout.write getNimPath() + stdout.resetAttributes() + stdout.flushFile() proc cleanExit() {.noconv.} = buffer.close() @@ -56,8 +59,11 @@ proc showError(output: string) = # Print only error message, without file and line number # e.g. "inim_1520787258.nim(2, 6) Error: undeclared identifier: 'foo'" # echo "Error: undeclared identifier: 'foo'" + stdout.setForegroundColor(fgRed, true) let pos = output.find(")") + 2 echo output[pos..^1].strip + stdout.resetAttributes() + stdout.flushFile() proc init(preload: string = nil) = setControlCHook(cleanExit) @@ -138,10 +144,13 @@ proc runForever() = validCode &= myline & "\n" let lines = output.splitLines # Print only output you haven't seen + stdout.setForegroundColor(fgCyan, true) for line in lines[currentOutputLine..^1]: if line.strip != "": echo line currentOutputLine = len(lines)-1 + stdout.resetAttributes() + stdout.flushFile() # Compilation error else: