views:

141

answers:

2

A Scala application does some data processing. It would be nice to show processing progress in percents overwriting previous value on change rather than appending a new value to what's already displayed. How to acheive this effect? I use Scala 2.8 on Linux.

+3  A: 

Your easiest options are to use the carriage return without linefeed "\r" or the backspace character "\u0008". If you backspace, you need to keep track of how many characters you've emitted so you can back up enough (and blank out any excess). If you carriage return, you need to rewrite the entire line (and write spaces to blank out any excess).

Rex Kerr
+1  A: 

Hi -

If you were programming in C/C++, the answer would unequivocably be "ncurses".

There is a curses implemention in Java you might be interested in:

Java Curses