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.