2

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.

5
  • 6
    Cut off the users hands?! Commented Jan 20, 2014 at 9:12
  • I think there's no way in standard c++. maybe you should use linux's API Commented Jan 20, 2014 at 9:13
  • 1
    You need to disable local echo on the terminal. Commented Jan 20, 2014 at 9:14
  • @ikh: I use ANSI codes to move the cursor, so something like that is okay, too! Commented Jan 20, 2014 at 9:15
  • @n.m: Something like this: ttynew.c_lflag &= ~ECHO; ? Can you elaborate a bit what it exactly does? Commented Jan 20, 2014 at 9:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You probably also want to set either non-canonical mode, or "raw" mode, and echo all normal (non-control) characters yourself. See man termios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.