How to keep the terminal from scrolling - c++

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.

Related

Why isn't my terminal running my updated C++ code?

I am a new programmer and I am trying to use the terminal on my Mac to compile and run the C++ code I write using the Sublime text editor.
I am able to get my code to run using the terminal, however, whenever I make changes to my code on sublime and then re-compile it on my terminal, my terminal doesn't recognize my changes and keeps on running my original code.
Does anyone know what might be happening?
Thank you so much!
I can think of two possibilities that spring immediately to mind. If you're changing your code in the editor, and that's not being reflected in the compilation, then it's likely to be one of the following. Either:
you're not saving the file in the location you think you are; or
you're not saving the file at all.
The easiest way to tell if one of these is the case is to introduce an error into your code(a), like:
int my hovercraft = full of eels;
and make sure the compiler complains about it.
If you're not saving it at all, do so. If you're saving it in the wrong place, you can usually find out where just by doing a Save As and seeing where the default location is.
If you're annoyed that you have to save, and that computers should just "work"(b), Sublime Text has an auto-save feature that may come in handy, courtesy of one Lucy Bain. Instructions (paraphrased) are duplicated here in case that site ever disappears:
Open Sublime
Find Settings and edit the user window (under Sublime Text 2 > Preferences for Mac, just Preferences for Windows).
Add the line "save_on_focus_lost": true.
Save and close the file.
At that point, whenever you click away from a particular file, it should save it.
(a) Some developers seem to have little trouble doing this without even trying :-)
(b) A not unreasonable expectation for a Mac user :-)

Moving cursor using code and opening folder

This is a very random and maybe a bit strange question that i thought of at 3AM. I was thinking about how code could make my day to day life easier. Every morning I wake up, open chrome to the facebook conversations with my boyfriend, and write "good morning". And thats when i thought about this hypothetical project(just out of curiosity, I wouldn't use it haha): making a code that i can just run that does all of this for me.
I could have a html file that could redirect to the facebook link(https://www.facebook.com/messages/t/boyfriend_name). But how would I go on to make the code open this file, then move the mouse to where its supposed to go (the white area where the user inputs the text) then insert the text then press send?
I'm not asking for any code help as I can imagine that is too much, but my question is: could this be achievable in C++?(This is what we've been studying at school so far). If not, what coding language should I use? Is the idea achievable without a vast knowledge in computer science? If yes, have you got any sources about opening files using C++, moving cursor etc.
Note:The OS this would happen on is Windows 10
To do what you want is possible by using AutoIT and to use it from C++ you can try AutoITX for C++. With AutoIT it's possible to detect windows, move the mouse and insert text, although a web page is like a blackbox to it, so you'll have to rely on relative pixel coordinates (it might not be very robust).

Find what was printed in the terminal

Is there anyway to check the terminal (Linux, and Windows) for characters at certain positions? I have external methods loaded via an explicitly loaded dll that prints certain characters onto the screen. I need to see if the functions printed what they were supposed to with minimal cross talk between the between the plugins. So at the core I am wondering if C++ has any feature for pulling chars off of the termial/command line?
This is not possible on VT100-like terminals (the kind popular in Linux.)
For Windows I can't say, but if you are using a cygwin terminal (not the power shell or the "DOS shell") the answer is again no.
You could use tmux or screen to set up a virtual terminal. The display state can then be captured, which seems to be what you want. But something in my brain is telling me that, whatever you are trying to do, this is probably not the right solution. What exactly is your problem?

Text-to-speech from my file/database?

I've made a little alarm program that is supposed to say one of a few things. There's a similar program on macs, but I couldn't find it for Windows, so I just wrote it in C++. Right now, I'm using a text file. The format of the text file I am parsing should help you to understand how the program works:
alarmName_Wakeup //There's a prefix alarmName, so I know when one list starts and another ends.
Cock-a-doodle-doo! //One thing to say.
Get out of bed! //Another thing to say.
Hello. Would you like to buy some guava juice? //Yet another thing to say.
So, I'm basically just trying to have the alarm randomly read one of these lines of text every five minutes until the user goes to his or her computer and presses the hotkey or clicks 'Stop Alarm'. I haven't been able to figure out how to get text-to-speech from a file or a database, though. I always need to have the text pasted in notepad or something, which is really shoddy. Please, help me figure out how.
The closest I can find to what I'm looking for is Open-SAPI, which works for both Linux and Windows.

How to get text to not scroll in a terminal

I am trying to write a C++ program where the screen updates every 1 second. However, I want the screen to be similar to htop, where it updates and does not have to scroll with each update. That way, I don't have a step-by-step iteration in my terminal.
Does anyone know what this style is called or how to program it?
Thanks!
The usual way is with something like ncurses. If you're on Windows, it has console functions built in so you can do the same without any extra libraries (though they do take a while to understand). If you only want one line of output, you can use a '\r' to return to the beginning of the current line and/or \b to backspace over previous characters (handy if yoy only want to overwrite a few little bits and pieces).
You'll need a library like curses (on *nix) or pdcurses for Windows (conio functions would probably still work on windows).