diff --git a/src/termio.c b/src/termio.c index c665769..2416c20 100644 --- a/src/termio.c +++ b/src/termio.c @@ -13,15 +13,25 @@ #define lfl_ECHO ((ECHO | ECHOE | ECHOK | ECHONL | ECHO)) // & ~(ECHOCTL | ECHOPRT | ECHOKE)) +/* + * NOTE: This function is taken from the GNU C Library (glibc), + * NOTE: specifically `glibc/termios/cfmakeraw.c`. + */ int termmode_raw(struct ct_term *restrict const term) { - term->termios.c_lflag &= lfl_RAW & ~(lfl_ECHO); - ct_applyterm(term); - return OK; + term->termios.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + term->termios.c_oflag &= ~OPOST; + term->termios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + term->termios.c_cflag &= ~(CSIZE|PARENB); + term->termios.c_cflag |= CS8; + term->termios.c_cc[VMIN] = 1; /* read returns when one char is available. */ + term->termios.c_cc[VTIME] = 0; + return ct_applyterm(term); } int termmode_canon(struct ct_term *restrict const term) { - term->termios.c_lflag &= (ISIG); - return OK; + /* TODO: inverse of termmode_raw */ + term->termios.c_lflag &= ~lfl_RAW & lfl_ECHO; + return ct_applyterm(term); } /* Set ncurses terminal mode (buffering, character processing,