views:

74

answers:

3

Right now, I have a console application I'm working on, which is supposed to display and update information to the console at a given interval. The problem I'm having is that with a carriage return, I can only update one line of text at a time. If I use a newline, the old line can no longer be updated using a carriage return.

What can I do here?

+5  A: 

You might be able to find a curses library variant that works on your platform.

Mark Ransom
A: 

This is a really ugly solution, but in a pinch you could always just clear the console entirely and then reprint everything. This strategy looks a bit ugly in some cases; it may make things look blinky.

Brian
+1  A: 

The correct answer is to use the curses library as mentioned by Mark. But if you're on Unix-like systems and can't be bothered with curses then the quick and dirty solution is to directly print out vt100 escape sequences:

http://ascii-table.com/ansi-escape-sequences-vt-100.php

I often do this especially in scripting languages that doesn't have a curses binding.

slebetman