A
A
Anton2018-06-11 21:12:28
C++ / C#
Anton, 2018-06-11 21:12:28

How to disable input buffering and echo output (termios.h, stdin)?

I want to make a console slider for a set of information, i.e. Need immediate response to key presses to switch slides.
Calling the setbuf(stdin, NULL) and setvbuf(stdin, NULL, _IONBF, 0) functions did not help me.
Prat's book talked about the ioctl function for unix-like systems. help me figure it out?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-06-11
@Friedhelm

As far as I understand, you need to switch the terminal to raw mode.
To do this, you need to set a bunch of flags in struct termios and call tcsetattr (().
Here's how it is implemented in libuv:

struct termios tmp;
      tmp.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
      tmp.c_oflag |= (ONLCR);
      tmp.c_cflag |= (CS8);
      tmp.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
      tmp.c_cc[VMIN] = 1;
      tmp.c_cc[VTIME] = 0;
  tcsetattr(fd, TCSADRAIN, &tmp);

Code torn from libuv sources: src/unix/tty.c -> uv_tty_set_mode().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question