2025-09-28 00:06:02 +10:00
|
|
|
#include "termio.h"
|
|
|
|
|
|
2025-09-28 13:19:40 +10:00
|
|
|
/* c_iflag bit masks */
|
|
|
|
|
#define ifl_RAW (~(IMAXBEL))
|
|
|
|
|
/* NOTE: the line below won't work, bad bitwise ops */
|
|
|
|
|
#define ifl_NOPARITY ((IGNPAR) & ~(PARMRK | INPCK | ISTRIP))
|
|
|
|
|
|
|
|
|
|
/* c_cflag bit masks */
|
|
|
|
|
#define cfl_NOPARITY (~(PARENB))
|
|
|
|
|
|
|
|
|
|
/* c_lflag bit masks */
|
|
|
|
|
#define lfl_RAW (~(ISIG | ICANON))
|
|
|
|
|
#define lfl_ECHO ((ECHO | ECHOE | ECHOK | ECHONL | ECHO))
|
|
|
|
|
// & ~(ECHOCTL | ECHOPRT | ECHOKE))
|
|
|
|
|
|
|
|
|
|
int termmode_raw(struct ct_term *restrict const term) {
|
|
|
|
|
term->termios.c_lflag &= lfl_RAW & ~(lfl_ECHO);
|
|
|
|
|
ct_applyterm(term);
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int termmode_canon(struct ct_term *restrict const term) {
|
|
|
|
|
term->termios.c_lflag &= (ISIG);
|
|
|
|
|
return OK;
|
2025-09-28 00:06:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set ncurses terminal mode (buffering, character processing,
|
|
|
|
|
* Key->SIG handling, and other termios(3) functionality).
|
|
|
|
|
*/
|
2025-09-28 13:19:40 +10:00
|
|
|
static inline int termmode(struct ct_term *restrict const term,
|
|
|
|
|
const enum crs_termmode mode) {
|
2025-09-28 00:06:02 +10:00
|
|
|
switch (mode) {
|
|
|
|
|
case TMODE_RAW:
|
2025-09-28 13:19:40 +10:00
|
|
|
return termmode_raw(term);
|
2025-09-28 00:06:02 +10:00
|
|
|
case TMODE_CANON:
|
2025-09-28 13:19:40 +10:00
|
|
|
return termmode_canon(term); /* ITS A CANON EVENT OHMAHGOH */
|
2025-09-28 00:06:02 +10:00
|
|
|
default:
|
|
|
|
|
/* defaulting is not possible. */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|