implement raw mode

This commit is contained in:
Emile Clark-Boman 2025-09-28 13:19:40 +10:00
parent 422a770028
commit b7c8c52212
2 changed files with 28 additions and 6 deletions

View file

@ -1,21 +1,41 @@
#include "termio.h"
int termmode_raw(struct ct_term *restrict t) {
t->termios.c_lflag &= ~(ISIG);
/* 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;
}
/* Set ncurses terminal mode (buffering, character processing,
* Key->SIG handling, and other termios(3) functionality).
*/
int termmode(struct ct_term *restrict t, const enum crs_termmode mode) {
static inline int termmode(struct ct_term *restrict const term,
const enum crs_termmode mode) {
switch (mode) {
case TMODE_RAW:
return raw();
return termmode_raw(term);
case TMODE_CANON:
return canon(); /* ITS A CANON EVENT OHMAHGOH */
return termmode_canon(term); /* ITS A CANON EVENT OHMAHGOH */
default:
/* defaulting is not possible. */
return 1;
}
}

View file

@ -16,4 +16,6 @@ enum crs_termmode {
TMODE_NORAW,
};
int termmode_raw(struct ct_term *const term);
#endif /* CURSETREE_TERMIO_H */