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

Boann
  • 48,794
  • 16
  • 117
  • 146
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

5 Answers5

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.

Mark Peters
  • 80,126
  • 17
  • 159
  • 190
  • Oh boy, that's an almost 6 year old bug. Thanks for finding the report. – BalusC Jun 22 '10 at 18:36
  • 17
    See comment #24 - "...the debug team does not currently have the time/resources to work on this. **Contributions would be greatly appreciated.** " – Stephen C Jul 08 '10 at 05:39
  • 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/Groovy – Bryan Hunt Sep 19 '11 at 14:49
  • 6
    @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. – Thorbjørn Ravn Andersen Sep 03 '12 at 13:00
  • 14
    I fixed the bug, it should be in 4.5 M4. – Philippe Marschall Nov 12 '14 at 16:43
  • 2
    @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. – arkon Aug 06 '15 at 21:58
  • This worked for me in Eclipse Mars 4.5, but installing SR1 (Mars 4.5.1) broke the feature again. – simon Oct 05 '15 at 08:32
  • 1
    According to https://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 (https://projects.eclipse.org/projects/eclipse/releases/4.6.0/plan). :/ – simon Oct 05 '15 at 08:49
  • 1
    This bug is still open in Eclipse 4.6.1 as far as I can tell. – eivamu Nov 30 '16 at 09:56
  • 1
    My fix is incomplete and causes other issues so we had to revert. – Philippe Marschall Jul 22 '17 at 18:55
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!

EMurnane
  • 381
  • 1
  • 3
  • "clearing the console with ...." how exactly? println() can't clear the already printed line on console! – KNU Nov 06 '14 at 20:57
  • 1
    It can push the already printed output upwards so that it gets out of the visible area of the console, effectively clearing the console. – simon Jun 22 '15 at 10:50
5

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

Павел
  • 677
  • 6
  • 21
3

Fixed, Eclipse Mars.

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

gagarwa
  • 1,426
  • 1
  • 15
  • 28
-4

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