As I said in my comments, it is hard to implement this correctly if you aim for some advanced Dynamic
features that work in the command line. However, you can surely use the carriage-return trick on the command line.
The only obstacle here is that Print
puts everything on a new line. However, if you write directly to stdout
, you don't have this problem. Consider the following small example:
progress[n_, max_] := WriteString["stdout",
"\r[" <> StringJoin@Table["#", n] <>
StringJoin@Table[" ", max - n] <> "]"
]
n=0; While[n++<20, Pause[0.2];progress[n,20]]

Edit
Is there any way to make this sensitive to the terminals window size?
Hmm, it's difficult, because you would need feedback from your window how large it is. I don't see a way to do this from the top of my head.
Would be nice to show additional information! Like ETA, Time Taken Already, Percentage
One downside of using \r
is that it doesn't delete the line and you have to ensure that your output is either of the same size or longer. Or you use another function to delete the line after an iteration.
Beside this obstacle, running time, ETA, or percentage can be implemented using a closure because you need to remember the starting time and other things.
An implementation for ETA
could look like this
Module[{start = Missing, eta, iter = 0},
ETA[max_Integer] := Module[{},
If[start === Missing, start = AbsoluteTime[]];
iter++;
eta = (AbsoluteTime[] - start)/iter;
WriteString["stdout",
"\r" <> ToString[Round[max*eta - iter*eta]] <> " Seconds left"]
]
]
and is then used like this
n = 0; While[n++ < 100, ETA[100]; Pause[.1]]
As you can see, on the first call it initializes the starting time and then, on each iteration, it updates the ETA.
An implementation for a sine-perculator can also be created but it requires that you have many, short iterations so that the display is updated often. However, I don't recommend something like this because it's hard to ensure that the progress display doesn't slow down your overall loop too much.

ProgressBar[] := With[{initTime = AbsoluteTime[]},
Function[
Module[{curr = AbsoluteTime[] - initTime, percolate},
percolate = Round[10*Cos[2*curr] + 10];
percolate = Append[ConstantArray[" ", percolate], "#"];
percolate =
StringJoin@
Join[percolate, ConstantArray[" ", 21 - Length[percolate]]];
Print[
TemplateApply[
"[`perc`] `time` Seconds",
<|
"perc" -> percolate,
"time" -> Round[curr, 0.1]
|>
]
]
]
]
]
pbar=ProgressBar[]; n=0; While[n++<12^4, pbar[]]
Dynamic
features are completely handled by the front end which has several links to the kernel exactly for the reason to be able to "ask dynamically for values" while the kernel is doing something. If you start a simple cmd kernel, you have one and only one link. If you run something, this link is blocked. So an enhanced command line kernel means that you (a) have to set up additional links to the kernel that you can use for inspection and (b) $\endgroup$Dynamic
. This however goes far beyond what an answer here can provide. There might be some hacky ways that provide simple feedback. E.g. you could print things during a loop like "$$$progress 12/100" and let you command line library interpret this and convert it into a progress bar instead of printing it line by line. My point is, "doing it right" is a lot of work. $\endgroup$