Reputation: 75
I'm trying to make a more-like application where the user's inputs are recorded but not printed. So I've turned off echoing, and turned off canonical mode to process inputs immediately.
Here's the code for this:
struct termios oflags, nflags;
tcgetattr(fileno(stdin), &oflags);
nflags = oflags;
nflags.c_lflag &= ~ECHO;
nflags.c_lflag |= ECHONL;
nflags.c_lflag &= ~(ICANON);
nflags.c_cc[VKILL] = 0; /* <Nada> */
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
exit(0);
}
And then to read the input and do stuff:
while(1){
c = getchar();
And then I process C as control basically.
So that works for the most part. Except whenever I press enter, while the processing works as expected, the input still gets submitted / flushed. And I get the little square brackets around the last line.
Any help would be appreciated. Thanks!
SOLUTION: Removing 'nflags.c_lflag |= ECHONL;' fixes it, I'd added that for another reason.
Upvotes: 2
Views: 68
Reputation: 75
Removing 'nflags.c_lflag |= ECHONL;' fixes it, I'd added that for another reason but I can get around using it too.
Upvotes: 1