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

5

84

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 :)

Jaeger answered 22/6, 2010 at 18:27 Comment(1)
I see the same symptoms in NetBeansObstacle
C
57

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.

Competitive answered 22/6, 2010 at 18:31 Comment(10)
Oh boy, that's an almost 6 year old bug. Thanks for finding the report.Jaeger
See comment #24 - "...the debug team does not currently have the time/resources to work on this. Contributions would be greatly appreciated. "Gabriellagabrielle
Incredible they haven't fixed it. There's like 20 duplicate/linked related bugs - seems like such low hanging fruit. Shitty Eclipse console makes lots of other stuff suck as well - SBT/Scala/GroovyAid
@BryanHunt apparently it is not important to the one making decisions on what to do for the next version of Eclipse. Apparently it is not important enough for you either.Elliellicott
I fixed the bug, it should be in 4.5 M4.Priam
@PhilippeMarschall I don't mean to diminish your hard work, but so far as I can tell, it's most certainly not fixed (using Mars release.) Printing backspace characters has no effect for me. Edit: It would appear the bug has indeed resurfaced, see the final two entries in the bug report linked in this answer.Cindy
This worked for me in Eclipse Mars 4.5, but installing SR1 (Mars 4.5.1) broke the feature again.Ewall
According to bugs.eclipse.org/bugs/show_bug.cgi?id=76936 the fix is planned for Eclipse 4.6 with a target release date of June 22nd, 2016 (projects.eclipse.org/projects/eclipse/releases/4.6.0/plan). :/Ewall
This bug is still open in Eclipse 4.6.1 as far as I can tell.Creath
My fix is incomplete and causes other issues so we had to revert.Priam
B
8

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!

Busse answered 22/6, 2010 at 23:18 Comment(2)
"clearing the console with ...." how exactly? println() can't clear the already printed line on console!Sparrow
It can push the already printed output upwards so that it gets out of the visible area of the console, effectively clearing the console.Ewall
M
5

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

Marola answered 10/5, 2020 at 19:54 Comment(1)
This worked in Eclipse IDE for Java Developers Version: 2019-12 (4.14.0). ThanksUnchristian
D
3

Fixed, Eclipse Mars.

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

Disturbing answered 25/7, 2015 at 0:52 Comment(1)
Unfixed in Neon.3 (System.out.println("x\by")).Pilgarlic
E
-4

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

Enravish answered 25/7, 2016 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.