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.
-
6Cut off the users hands?!Ed Heal– Ed Heal2014-01-20 09:12:59 +00:00Commented Jan 20, 2014 at 9:12
-
I think there's no way in standard c++. maybe you should use linux's APIikh– ikh2014-01-20 09:13:35 +00:00Commented Jan 20, 2014 at 9:13
-
1You need to disable local echo on the terminal.n. m. could be an AI– n. m. could be an AI2014-01-20 09:14:23 +00:00Commented Jan 20, 2014 at 9:14
-
@ikh: I use ANSI codes to move the cursor, so something like that is okay, too!gartenriese– gartenriese2014-01-20 09:15:32 +00:00Commented Jan 20, 2014 at 9:15
-
@n.m: Something like this: ttynew.c_lflag &= ~ECHO; ? Can you elaborate a bit what it exactly does?gartenriese– gartenriese2014-01-20 09:18:10 +00:00Commented Jan 20, 2014 at 9:18
Add a comment
|
1 Answer
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.
1 Comment
n. m. could be an AI
You probably also want to set either non-canonical mode, or "raw" mode, and echo all normal (non-control) characters yourself. See
man termios.