When I press enter while my terminal program runs, a new line is added. How can I disable this? I don't want to use ncurses. I am on Ubuntu.
Asked
Active
Viewed 517 times
2
-
6Cut off the users hands?! – Ed Heal Jan 20 '14 at 09:12
-
I think there's no way in standard c++. maybe you should use linux's API – ikh Jan 20 '14 at 09:13
-
1You need to disable local echo on the terminal. – n. m. could be an AI Jan 20 '14 at 09:14
-
@ikh: I use ANSI codes to move the cursor, so something like that is okay, too! – gartenriese Jan 20 '14 at 09:15
-
@n.m: Something like this: ttynew.c_lflag &= ~ECHO; ? Can you elaborate a bit what it exactly does? – gartenriese Jan 20 '14 at 09:18
1 Answers
1
Following up n.m's hint, I found this and came up with this:
static struct termios t;
tcgetattr( STDIN_FILENO, &t);
t.c_lflag &= ~ECHO;
tcsetattr( STDIN_FILENO, TCSANOW, &t);
This seems to block all input to the terminal.

Community
- 1
- 1

gartenriese
- 4,131
- 6
- 36
- 60
-
You *probably* also want to set either non-canonical mode, or "raw" mode, and echo all normal (non-control) characters yourself. See `man termios`. – n. m. could be an AI Jan 20 '14 at 10:08