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.
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
Your indentation sucks. :-)
I agree. Hrrm. Who ate it?
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.
Good idea.
/ Mirar
Previous text:
2003-12-14 15:17: Subject: convenience function
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!)
things like that might be good for the hacks on the (not yet officially opened) pike community site.
greetings, martin.
Isn't it better to use Tools.Install.ProgressBar?
/ Martin Nilsson (saturator)
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
The max is unknown until the progress function is called. It can be 0, or it can be billions.
I could wrap Tools.Install.ProgressBar inside such a function too, but it seems kind of superflous.
/ Mirar
Previous text:
2003-12-14 16:28: Subject: convenience function
I am assuming that you have a fix length progress indicator now. If so, then just set max to 100 or whatever is convenient.
/ Martin Nilsson (saturator)
pike-devel@lists.lysator.liu.se