improve term RAW mode (REF: glibc)

This commit is contained in:
Emile Clark-Boman 2025-09-28 22:34:48 +10:00
parent 059606b5ef
commit 7ff74c0d67

View file

@ -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,