Hello,
I'm trying to create a simple progress bar indicator. I'd like to print (update) the bar always in the same line of the screen. Looking at the source code of choosenim, I discovered eraseLine(). So, I made the following toy code:
import strutils, terminal
proc showBar(content: string) =
eraseLine()
stdout.write("[$1]" % [content])
stdout.flushFile()
var lastPos = 0
var content = repeat(' ', 10)
for progress in 0..<10:
content[lastPos] = '#'
lastPos.inc()
showBar(content)
However, I am getting an error.
Traceback (most recent call last)
temp.nim(13) temp
terminal.nim(660) showBar
terminal.nim(389) eraseLine
os.nim(154) raiseOSError
Error: unhandled exception: Invalid Identifier.
[OSError]
Without the eraseLine(), the result is the following:
[# ][## ][### ][#### ][##### ][###### ][####### ][######## ][######### ][##########]
What am I doing wrong ?
TIA
You are using undefined eraseLine proc
The correct is stdout.eraseLine()
import strutils, terminal
from os import sleep
proc showBar(content: string) =
stdout.eraseLine
stdout.write("[$1]" % [content])
stdout.flushFile
var content = ' '.repeat 10
for progress in 0 ..< 10:
content[progress] = '#'
sleep 100
showBar content