Re: Represent work in progress on std out



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();
}
}
.



Relevant Pages

  • Re: Use a DC in a worker thread
    ... opportunities to update the progress bar, one for each little piece you did. ... typedef void ... CWnd * parent = NULL); ... static void SetRange; ...
    (microsoft.public.vc.mfc)
  • Suspend 2 merge: 44/51: Text UI plugin.
    ... Here's our plugin that is used to display text output on the console. ... When the console loglevel is 0 or 1, the user gets a nice progress bar. ... +static int lastheader_message_len = 0; ... +static void unblank_screen_via_file; ...
    (Linux-Kernel)
  • Re: An object reference is required for the non-static field, method, or property
    ... static void Main(stringargs) ... it's just that you'll make progress ... World class .NET training in the UK:http://iterativetraining.co.uk ...
    (microsoft.public.dotnet.languages.csharp)