How to hide my input on my terminal? [duplicate] - c++

This question already has answers here:
Hide user input on password prompt [duplicate]
(3 answers)
Closed 6 years ago.
I'm on Ubuntu with C++
How do I hide the red box (user input) as shown in the image above on my terminal ?
char *MESSAGE=getpass("");
the code above would leave a blank line after each input and I dont want the message to be hidden while the user typing the message.
In short, I want the message to be visible as I'm typing the message but goes invisible on my terminal as soon as he entered.
EDIT : Can someone please enlighten me on how this question is duplicated to that thread?.

You could clear the terminal after a message has been sent and reprint the whole chat afterwards.

If you can print the name first and then read the input message, I think your problem might be solved. Have you tried that?

You cannot do that in a reliable and portable way with only functions from the standard C library, not even with Posix one.
If you now that you are using a Windows console, the Windows console functions could allow you to erase specific portions of the screen, if you know that you are using a terminal emulator conformant to one standart (VT100, xterm, ...) you can output special control sequence to do the same.
The only portable way would be to use a screen management library like curses that will do the low level work for you.

Related

Using system() function in c++ cause command prompt window appear and disappear [duplicate]

This question already has answers here:
Opening a document programmatically in C++
(4 answers)
Closed 7 years ago.
I use system() function to open a pdf in c++. It works correctly but while opening pdf, the command prompt window appear and disappear. I don't want this window to appear. What should I do?
You probably want a different higher-level API. What that would be depends on what platform you are on, what framework you are using.
Something like win32's ShellExecute or this in MacOSX/Cocoa:
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
[workspace openFile:aFilePath];
If you are using win32, then use
ShowWindow(GetConsoleWindow(),SW_HIDE);
This will do the trick.

How do i get my c++ program to "press keys" on its own?

Im writing a little C++ progam but got to a point from which on i could not go on:
I want my program to control an external program using a certain combination of keys.
Yes, this sounds like a horribly unclean workaround, but thats what i want to do ;)
To be more specific:
I want my little C++ program to control the already running program elinks (a text based internet browser) by pressing the "esc" then "v" and then "h" -keys (this is used to toggle between html and plain text output in elinks).
But unfortunately, I do not know how to get a C++ program to type a certain combination of keys (...if this is possible at all).
I already tried the search function but wasnt able to find a solution.
It would be very kind of you, if someone could give me a hint on what to do here.
Thanks,
Spoekenkieker
P.S.: Im running Linux
If you have control over how to start the elinks browser, you can start it under the GNU screen terminal multiplexer and use its stuff command to send key inputs:
https://unix.stackexchange.com/questions/13953/sending-text-input-to-a-detached-screen
This way you're not required to learn the complications of X Windows programming.

In a C/C++ program, how can I write bold text in the terminal? [duplicate]

This question already has an answer here:
Bold text through C++ write statement
(1 answer)
Closed 8 years ago.
is it possible to format the console output, like writing in bold, of a C/C++ program? I'm talking just about the console output (so no high-level) e.g.:
std::cout << "\b this is bold";
std::cout << " this is not";
I hope there are some libraries, this program is intended for Linux.
Thanks for advises.
That is not a question about C or C++ but rather about your particular console. Any answer is specific to your target, and possibly in Linux dependent the specific particular terminal emulator.
In most cases a terminal, terminal emulation, or in case of Windows a console window, there will be no support for bold as such - you can often control the colour and brightness of a fixed font however. You can do this in a number of ways - again platform specific - for example through a library such as curses, by sending terminal specific escape sequences, or in Windows through the Win32 Console API.
Without knowing the specific platform, it is not possible to give a specific answer, and even then that answer may not be portable to other platforms.

Prevent mixing of console output and written text

I have a C++ console application that prints some output constantly while it also accepts commands (using std::cin) from the user - output and input happen in separate threads.
If I write a text while some output appears the written text is mixed with application output. How can I prevent this behaviour?
To solve this problem, I need to display the program one line above the line where the text is typed. I'd inspire myself in Minecraft Bukkit server's solution - however I need the same for C++.
Assuming you want the output to appear while things are being typed, you'll need some screen control facilities to have the output go somewhere different than the input area. If I were tasked to implement something like this writing to a terminal I would refresh my ncurses experience. I realize you are on a Windows console and I have no idea if the Windows console is capable of the screen control needed to make it happen.
You can possibly tie custom stream buffers into std::cin and std::cout using the curses functionality under the hood but it may not be worth it. In any case, it isn't entirely trivial.
There's a windows port of ncurses called pdcurses. But if you are using visual studio there's a simple function provided called SetConsoleCursorPosition()

How to read standard input continuously? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C/C++: Capture characters from standard input without waiting for enter to be pressed
Is there a way to read standard input continuously? I want to make an X and O game and I want the player to use the the arrows to move its position on the grid. I can't use cin because it requests you to press enter to get the input data into variables. So, does a function or an object doing that exist?
For console (text) applications you'd use something like ncurses, which does terminal 'GUI' controls.
For graphics applications you would use something like SDL which enables event-driven programming.