Linux C++: How do I display my Text application output outside of stdout? - c++

My objective is to create a game playable in the Linux terminal. However, there is a concept that I don't know how to name, so my searches are coming up empty handed.
How do programs like iptraf access the output on such a low level that they can modify the background, foreground and character content of each cell as well as capturing all keyboard input instead of the shell?
I assume that somewhere, there exists a 2D array that can be modified to display custom terminal window content, but I can't name this concept so I can't search for it. What concept am I describing?

As per the idea of this meta-answer, I'm answering this question so that i will get removed from the "unanswered" listing.
The concept you are looking for was described by #123, it's called ncurses.

Related

How to split c++ console screen into parts?

I'm making a c++ console application, I want to split the console screen into parts and every part will print an individual output, to be more clear the console screen should be close to the design of Far Manger console app screen, but I have no idea how to start and what libraries should I use to do so. Sorry if it's a naive question but I seriously have no idea and couldn't find what I want when I made a search.
If you want control of console text, such as positioning, or representation in a windowed fashion, have a look at ncurses.
Your target system may support escape sequences (see the wiki ANSI Escape Codes), or have particular API (as mentioned in the above comments) to implement console manipulation.

How to get an int as input and project a double as output in an OpenGL C++ program?

I'm developing a OpenGL application in C++ however I require the user to input an int and the project to output a double plus some text. What would be the best way to go about this?
There's no text input function in OpenGL. You'll have to use an API on top of openGL, for example manage the keyboard entry with the basic GLUT keyboard functions.
For the output, you have to draw it as part of your graphic output as explained in this SO question.
Of course you don't need to reinvent the wheel from scratch and may consider more elaborate API than Glut, as discussed here.
Edit: Just seen today this tweet from Evan Todd with a link to his 160 lines of C++ implementation of in-game console on github. It's based on OpenGL/glfw. His approach could interest you as well.
Your job can be split into two part
Taking integer input from user
Show double + extra text it on your window
obviously second part is the easy part, use glutStrokeCharacter to show your double + text referred here
The first part is little bit tricker, you can make a TextEdit like widget using the glutStrokeCharacter & glutKeyboardFunc. The job of the TextEdit will to show the user original int input. just register the keyboard using glutKeyboardFunc & on the call back draw the original int inside the TextEdit widget.
glutKeyboardFunc is referrence here here
suggestion, draw a nice rectangle just behind the TextEdit's to make it seems actual user input :). Happy coding
Just found this actually which does exactly what I'm looking for. Thanks for all the responses.
https://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/

How to draw to a certain part of the console/terminal?

I'm curious to know how you can draw/update a certain region of the terminal/console. Is there any cross-platform libraries to do so?
The reason I want to know is because I am developing an instant message command line application, and I was curious to know how I can update the message viewer (where all the messages go) separately to where you write commands/text for other people in the chat. Obviously if I just tried to get input and write to cout then the input the user is entering and the messages would be "interfered" (by interfered I mean split in multiple lines).
I was thinking of using two stream objects: one to store the view (messages/output from the server) and one to store the input from the user, and just redraw whenever required. However, this seems inefficient and it requires me to clear the screen (in which case I don't know how to clear the screen efficiently and in a cross-platform manner).
I was also thinking of just switching to Qt/wxWidgets as it might simpler to make a GUI.
Use ncurses library to write text-based user interfaces in a terminal-independent manner.
As suggested by #Naruto, ncurses is a good way to go. At a much more basic level, you can also just use ANSI escape codes to move the cursor around the screen too:
For example, to position the cursor at line 5, column 23, you can enter this
echo -n "\033[5;23H"
There are more examples here.

What function to use to select text?

I search a lot of on internet but didn't find some good copy-paste manager for windows 7. I want to make something to easy copying multiple texts. So my question is what function to use in c++ to select some text that will be copy. The plan is that every time when is pressed CTRL+C selected text copy to some txt file, and when is pressed CTRL+V application show you what is in that file, and you can use what text you need. The main question is how to select text, what function to use? Platform win 7.
You should read up a bit on how the Windows clip board works. Every application in the system can place objects of different formats (including text) on the clip board. The easiest way to grab the content out of any applications is probably to somehow monitor the clip board and get the data from there.
For the pasting part, if I remember correctly, there is a special kind of "owner-handled" data on the clip board. Using that, the data isn't actually published on the clip board, only a reference to the application currently having the clip board data. Whenever the data is pasted the application gets notified that it should send the data to the recipient. It should be possible to exploit that functionality to get your application to pop up a windows where the user can select what data to paste.
Please see my articles on clipboard viewer implementation, including common pitfalls:
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/6
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/common-general-clipboard-mistakes

How to keep the terminal from scrolling

I am writing a simple program in C++ to be run in a terminal window. I would like the output text to be locked in position on the screen. Instead of each new line appearing at the bottom of the screen and pushing everything up, I would like to be able to change a line of text or some characters in a line of text, while keeping other lines above and below it static. I know I have seen this done in terminal, and I believe it was done with C++, but I can't find any documentation on it. I cannot even think of what this type of display might be called. My google fu has failed me; please help. If you can tell me what commands/library to use, that would be great, but even being able to tell me what commands accomplish this in a programming language other than C++ would give me more to go on than I have now.
You want ncurses, a library for displaying text on a terminal.
If you are programming for Microsoft Windows, try googling for Win32 Console Functions.