Re: Represent work in progress on std out
- From: Simon <count.numbers@xxxxxx>
- Date: Thu, 29 Jun 2006 12:12:54 +0200
Is there a way in java to represent work in progress( not using a gui)
on command line?
I guess your problem is that you want to overwrite the old progress bar. You can
try to use \b. You can try the following. It needs some obvious improvements,
but it works, at least on my console (Linux). I would be interested to learn if
it also runs on Windows and other consoles. It definitely doesn't work when
System.out is a file, though :-)
public class ProgressBar {
private static final String DELETE =
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
private static void printProgress(int progress, boolean firstTime) {
if (!firstTime) {
System.out.print(DELETE);
}
System.out.print("[");
int hashes = 40 * progress / 100;
for (int i = 0; i < hashes; i++) {
System.out.print("#");
}
for (int i = 0; i < 40-hashes; i++) {
System.out.print(" ");
}
System.out.print("] ");
if (progress < 10) { System.out.print(" "); }
System.out.print(progress + "%");
}
public static void main(String[] argv) {
for (int i = 0; i <= 100; i++) {
printProgress(i, i==0);
try {
Thread.sleep(50);
} catch (InterruptedException e) {}
}
System.out.println();
}
}
.
- Follow-Ups:
- Re: Represent work in progress on std out
- From: Simon
- Re: Represent work in progress on std out
- From: Simon
- Re: Represent work in progress on std out
- References:
- Represent work in progress on std out
- From: Petterson Mikael
- Represent work in progress on std out
- Prev by Date: Re: a little confused about packages...
- Next by Date: Re: Represent work in progress on std out
- Previous by thread: Re: Represent work in progress on std out
- Next by thread: Re: Represent work in progress on std out
- Index(es):
Relevant Pages
|