How to preserve n lines of console for the same output? - c++

I'm using console intensively to report the status of my program.
There are different modules that print different messages of different importance.
What I want is to preserve the first two lines of the console to print some important information while allowing the other information to be printed in the rest of the console. Even if the other information exceeded one page of console and had to scroll down, I want the first two lines to stay there.
Is there some way to do this?
Currently, I'm printing using printf with colors.
I'm working on Linux and I'm using guake terminal (zsh). I'm using both C and C++ in my code so both are fine for me.

Related

How to make SAS Enterprise Guide show only the latest data created in Output Data?

Also how to make SAS Enterprise Guide to go to Output Data tab after a successful run instead of Results tab?
It's going to go to Results if you produce results, I don't think there's any way around that. You will get all of the datasets produced in that program in the Output Data tab, as well.
However, I'm going to venture a guess here: you're using EG like a single window programming environment, right? You have a single long program? If so, then the answer is simple: split your program up. EG is intended to have lots of small programs, each of which have a very specific goal and output. Think of it as steps: each program node is just one step, could be even just one data step. Then you link several programs together, in sequence, and run them all as a process flow (or an ordered list).
If you treat it that way, then it works very much like you say: you can have one program that has one output dataset and no results window, if your last program in a process flow just produces one dataset and no results.

C++ Quantlib output to console window

I am learning how to use quantlib to price derivatives. What is the best way to output some of the Quantlib specific classes to console window? For example
shared_ptr<YieldTermStructure> forwardCurve(new InterpolatedDiscountCurve<LogLinear>(dates,discountFactor,Actual360()));
Handle<YieldTermStructure> forwardingTermStructure(forwardCurve);
shared_ptr<IborIndex> euribor(new Euribor(3*Months,forwardingTermStructure));
What will be the best way for me to output forwardCurve to and euribor to console window? Then I can see the intermediate result of the code to see if they are as expected.
Many thanks.
There's no predefined way to output those classes to console, but you can use their inspector to output the relevant data (so, e.g., you can call forwardCurve->times() and forwardCurve->discounts() to inspect the values you're interpolating) or you can call their methods to see the results of their calculations (e.g., forwardCurve->discount(d) to retrieve the discount factor at a given date, or euribor->fixing(d) to retrieve the expected index fixing). The returned values can be written to console.
As an alternative, you might consider stepping through the code inside a debugger. In modern IDEs, this will give you the same information more easily.

SetDlgItemInt / GetDlgItemInt APIs and thousands separator confusion

For my dialog window I'm filling in numbers into edit boxes using the SetDlgItemInt API. It does a great job by also adding a thousands separator (example for US: 1,024.)
But when I try to read the integer back from the edit control using GetDlgItemInt API, it fails when the number has a thousands separator.
So what am I doing wrong? These two APIs must be compatible with each other.
PS. I can obviously format these numbers myself. This question is about these two specific APIs that supposedly do formatting for me.

help with type of window dialog resource needed

I am writing a windows program (no mfc) and need to output a status line to the operator every few seconds or so. I tried using rich text boxes but after so many hours it seems to hang up. Does anybody have an suggestions on what I can use instead?
People mentioned that my buffers might have been exhausted. I thought I had planned for that. After I had about 1000 lines displayed I would take the first 500 and remove them using the select and cut options in rich text boxes. I still ran into the same problem.
This question appears relevant, and this one too. But they don't give any concrete recommendations for an alternative to rich text boxes.
You might try the Scintilla control (scintilla.org) which does not appear to have any hard limitations on text size. It has a permissive license. It is used by many text editors such as Notepad++, Notepad2, Code::Blocks, FlashDevelop. I haven't tried it personally but there from the documentation it looks easy to use it in a Windows API application. Of course, it might be overkill for your purposes.
If you keep appending to the text in the control every few seconds for hours then you are probably running into some memory constraint on the control or the process. I think you would have this problem with any control you choose given update frequence and how long you're running the program.
Have you considered implementing a simple circular buffer for the content of the text box? Say only keep the last hour's messages. You could maintain a separate log file for history if the operator needed to go back in time for hours.
I ended up writing my own control to do this, essentially duplicating the Output window in Visual Studio. It was a success, but it ended up being much more code than I thought it would be when I started - I insisted on features such as auto-scrolling when the cursor was on the last line, select/copy, bold text, etc. It was backed by a std::deque so I could limit the number of lines stored for the window.
Unfortunately the code belongs to a former employer so I can't share it here.

(C++) Can you add a direct link into a C++ program without a GUI?

I was wondering if you can add a link to a website in a C++ program running in the CMD Prompt type window (No GUI)
If it's possible can some one please give me a few examples?
You mean output text in the command prompt that the user can then click on? No, not unless the terminal supported it. Linux terminals usually autolink text that matches a URL pattern, so you could just printf("http://stackoverflow.com/\n"); and it would be clickable, but that's up to the terminal, not your program
When you write 'direct link' it is not clear if you mean clickable text or a means to open a url. At any rate, command line programs usually respond to command line parameters. Your program could open a url in the default browser in response to a command line flag. On Windows, you could call ShellExecute - on other systems, system might be appropriate.
It depends. In Windows, for example, yes, it's entirely possible, though somewhat non-trivial. You can receive mouse events via ReadConsoleInput, so in theory it's a fairly straightforward matter of reading the input event, and if it's a mouse click over the area you've defined as a link, you direct the user to the link as you see fit -- if you want to display the web site in text mode, that's possible (though, again, distinctly non-trivial). If you want to start up the user's normal web browser, that's a lot simpler (normally just ShellExecute the URL).
In reality, the details get a bit ugly. You have to enable mouse input for it to work at all. ReadConsoleInput gives you an INPUT_RECORD, which is a union of a number of different input record types, one of which is a mouse input record. By the time you get to react to a mouse click, your code is nested fairly deeply. None of it is unmanageable by any means, but unless you already have a fair amount of experience with Windows console programming, it might easily take most of a day (maybe even a bit more) before you have it working, rather than the hour or two you'd initially guess.
That, of course, is strictly for Windows -- if you ever want to port the code to another system, I'd guess there's a pretty good chance you'd be looking at a complete rewrite. For GUIs there are a fair number of cross-platform libraries, but text mode mouse operations aren't nearly so well supported.