tags:

views:

104

answers:

5

I don't know how to explain this very well, but here's a shot at it. Don't hesitate to ask for clarification, please.

Suppose I have a console that displays numbers that change with certain events. The best example would be a "plane" instrument that shows altitude, direction, wind, etc. Like so:

Altitude: 9876ft      Direction: NE
Wind:     5km, NE
...

I only have a Windows and Linux console and I want these values to refresh themselves in place.

Is this simple? C or C# code and any pointers would definitely help.

Thanks.

A: 

Use something like ANSI code sequence to erase the console and write over again.

If you just want to update one line, in UNIX you can use the the \r control character to go to the beginning of the line without going to the next one. Any further writing will override what you wrote.

Steve Schnepp
+4  A: 

The curses library is the usual way to handle this, and it is reasonably portable.

caf
A: 

Take a look at this thread. I think the solutions provided there would fit your needs.

erelender
+2  A: 

I would use Console.SetCursorPosition method for this purpose.

Ihar Voitka
The question mentions the Linux console, which this isn't going to be too helpful for.
caf
This method exists in Mono Class Library, so I assume it will work on Linux too.
Ihar Voitka
+1  A: 

you can always use something like

for(;;)
{
  printf("value: %d", something);
  update_value();
#ifdef WINDOWS
  system("cls");
#else
  system("clear");
#endif
}

but it's the dirtiest way to do it =)

tr3