Skip to content

Commit

Permalink
* Colorized output (red for errors, cyan for results)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiRegiani committed May 4, 2018
1 parent ef9a5ea commit f1e8ad6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions src/inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f1e8ad6

Please sign in to comment.