3

I'm on Ubuntu with C++

Image

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?.

Lozy
  • 160
  • 4
  • 11

3 Answers3

2

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

Shiro
  • 2,610
  • 2
  • 20
  • 36
  • 1
    i know there's a way of clearing the terminal but wouldn't that clear my entire screen leaving the latest message only ? – Lozy Jun 23 '16 at 16:17
  • 1
    Clearing the terminal means that everything that was written on it will vanish. Since you want the chat to be visible you can print the whole chat after every input. This assumes that you are storing the chats content somewhere. – Shiro Jun 23 '16 at 16:20
0

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

0

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.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252