0

I'm developing some application in which I want to manipulate some data comming from the embedded system. So, what do I want to do is that I want to display the values which are comming on the same position where they were before, leaving the static text on the same place and not using new line. Being more specific, I want to output my data in form of a table, and in this table on the same positions I want to update that data. There is some analogy in Linux, when in the terminal there is some update of the value(let's say some progress) while the static text remains and only the value is changing. So, the output should look like this:

Some_data: 0xFFFF

Some_data2: 0xA1B3

Some_data3: 0x1201

So in this case, "Some_data" remains unchanged on the same place, and only the data itself is updated. Are there maybe some libraries for doing that? What about Windows Console Functions? Also, it would be very nice if it could be made in such a way, in which the console would not flick, like when you clear the console and print something back. Any hints or suggestions? Thanks very much in advance guys!

P.S. There is no need to write the code, I just need some hints or suggestions, with very short examples if possible(but not required).

6
  • You're looking for something like ncurses -> invisible-island.net/ncurses Commented May 4, 2017 at 9:40
  • Not something, but ncurses. Period. Commented May 4, 2017 at 9:56
  • 1
    You aren't very clear on what you target platform is. Commented May 4, 2017 at 10:01
  • @CodeGorilla I write windows application. After I finish with it, I will possibly port it to Linux, but I want to write it for windows firstly. Commented May 4, 2017 at 10:08
  • If your terminal accepts ansi escape sequences you can use them the same way as you would change colors: rrbrandt.dee.ufcg.edu.br/en/docs/ansi/cursor Commented May 4, 2017 at 10:14

1 Answer 1

0

On a *nix system you have two options.

1) If you want to manipulate the entire console in table form like you ask, then ncurses is the best option. The complete reference can be found here.

As you can see, that package is quite heavyweight and can often be overkill for simple projects, so I often use . ..

2) If you can contain your changing information on a single line, use the backspace escape char \b and then rewrite the information repeatedly to that line

For example, try this . . .

#include <iostream>
#include <chrono>
#include <thread>

using namespace std;

void writeStuff(int d)
{
    cout << string(100,'\b') << flush;
    cout << "Thing = " << d;
}

int main()
{
    cout << "AMAZING GIZMO" << "\n============" << endl;
    while(1) {
        writeStuff(rand());
        this_thread::sleep_for(chrono::milliseconds(250));
    }
}

For a real world example, the sox audio console playback command uses this technique to good effect by displaying a bar chart made of console characters to represent the audio playback level in real time.

Of course, you can get more creative with the method shown above if your console supports ANSI escape sequences.

Sign up to request clarification or add additional context in comments.

4 Comments

Well, I guess that the size of the library is not very important here, because besides the displaying of the values, there is communication part, processing part and so on, and I want the output to be very informative and comfortable, so I don't have to constantly shift up/down the console(I use ConeEMU instead of plain windows console, but anyway...).
why don't just cout << "AMAZING GIZMO\n============\n"; instead of printing 3 separate strings?
... errr that line is kinda disposable anyway. Format it however you like to read it in your code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.