Your indentation sucks. :-)
Maybe it should set inited to 0 or something when it prints the newline? Then it would be possible to reuse the bar if the process has multiple steps.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2003-12-14 15:05: Subject: convenience function
Any good place to put this convenience function? I seem to use it a lot, so I thought I should just add it to the tree.
function(int,int:void) progress_bar(string name,int steps) { int inited=0; int lastpos=0;
return lambda(int n,int m) { if (!inited) write(name+"["+"."*steps+"]\r"+name+"["),inited=1; int pos=(steps*n)/m; if (pos!=lastpos) { write("#"*(pos-lastpos)); lastpos=pos; } if (n==m) write("\n"); }; }
It will output a progress bar, like
my progress: [##########_ ]
and end it with \n when it's full.
/ Mirar