Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 381
BalusC Avatar asked Jun 22 '10 18:06

BalusC


People also ask

How do you remove backspace in Java?

To get your desired Output i.e. Hell you need to add a space character after \b . Because \b will only move the cursor (virtually) to 1 position backward but it won't delete it. All you can do is replace the character to be deleted by space .


1 Answers

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.

like image 112
Mark Peters Avatar answered Sep 22 '22 07:09

Mark Peters