How to get backspace \b to work in Eclipse's console?

JavaEclipseBackspace

Java Problem Overview


I'm creating a little Java application which should have a progress indicator with percentages. In every loop it uses backspace \b to remove the displayed progress before displaying the next percentage.

Here's a simplified example:

public static void main(String[] args) throws Exception {
    System.out.print("Progress: ");
    for (int percentage = 0; percentage < 100; percentage++) {
        System.out.print(percentage + "%");
        Thread.sleep(10); // Stub for "long running task".
        int length = String.valueOf(percentage).length() + 1;
        while (length-- > 0) {
            System.out.print('\b');
        }
    }
    System.out.println("finished!");
}

This works perfectly in command prompt, but the backspace character isn't recognized in Eclipse's console (Galileo build 20090920-1017). It instead displays an empty square denoting an unknown character. See screenshot:

alt text

How do I get Eclipse to "display" the backspace properly? I.e. let it remove the previous character.

This is actually no showstopper since it will just be run in command console, but it would be just nice to get it to work in Eclipse as well :)

Java Solutions


Solution 1 - Java

Eclipse Bug #76936. I wouldn't count on them to fix it, and there are no workarounds listed.

You might have luck finding a plugin that contributes a more advanced console.

Solution 2 - Java

Well, it's true you can't use backspace \b to remove the displayed progress, but you could remove it by clearing the console with a loop calling println. Of course this kluge won't clear your log file!

Solution 3 - Java

Now they fixed it, but it's disabled by default. You should enable it via Interpret ASCII control characters in console preferences.

Solution 4 - Java

Fixed, Eclipse Mars.

Note, I wouldn't use it to do constant updating, as the eclipse console lags.

Solution 5 - Java

use: System.out.print("\b ") inside the while loop, instead of System.out.print('\b');

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBalusCView Question on Stackoverflow
Solution 1 - JavaMark PetersView Answer on Stackoverflow
Solution 2 - JavaEMurnaneView Answer on Stackoverflow
Solution 3 - JavaПавелView Answer on Stackoverflow
Solution 4 - JavagagarwaView Answer on Stackoverflow
Solution 5 - JavaFisho2008View Answer on Stackoverflow