diff options
| author | _ov4 <ov4@ov4.org> | 2026-09-21 10:54:49 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-09-21 10:54:49 +0000 |
| commit | 83fa0a85281118103b4f8bf82dcb25cacb42d982 (patch) | |
| tree | da185721a7332471d6b1da593b60a5cf794d28f0 /include/line | |
| parent | b63192d96dc57ab284d4238d114bdd935686dd70 (diff) | |
add raw mode
Diffstat (limited to 'include/line')
| -rw-r--r-- | include/line/mode.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/line/mode.h b/include/line/mode.h new file mode 100644 index 0000000..8811e66 --- /dev/null +++ b/include/line/mode.h @@ -0,0 +1,59 @@ +#pragma once + +#include <unistd.h> +#include <termios.h> +#include <stdlib.h> + +using namespace std; // TODO: remove + +namespace ov4 +{ + +inline termios attr; + +void disable_raw() +{ + tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr); +} + +void enable_raw() +{ + termios attr_raw; + tcgetattr(STDIN_FILENO, &attr); + tcgetattr(STDIN_FILENO, &attr_raw); + + // LOCAL + + // disable + // echo + // canonical + // signal + // disable post-input processing, aka control-V + attr_raw.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN); + + // INPUT + + // disable + // software flow control, aka control-S/Q + // \n and \r conversion + attr_raw.c_iflag &= ~(IXON | ICRNL); + + // OUTPUT + + // disable + // post-output processing + attr_raw.c_oflag &= ~(OPOST); + + // misc + attr_raw.c_iflag &= ~(BRKINT | INPCK | ISTRIP); + attr_raw.c_cflag |= ~(CS8); + + atexit(disable_raw); + + // TCSAFLUSH + // the change shall occur after all output written to fildes is transmitted + // and all input so far received but not read shall be discarded before the change is made + tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr_raw); +} + +} |
