// Turn cbreak on or off. man stty says cbreak is just -icanon and // -cbreak is just icanon. man termios has a section "Canonical and // noncanonical mode" and explains that the `ICANON` flag in `c_lflag` // (“local mode”) controls it: /* In noncanonical mode input is available immediately (without the user having to type a line-delimiter character), no input processing [ISIG and ECHO*] is performed, and line editing is disabled. The read buffer will only accept 4095 chars; this provides the necessary space for a newline char if the input mode is switched to canonical. The settings of MIN (c_cc[VMIN]) and TIME (c_cc[VTIME]) determine the circumstances in which a read(2) completes; (...) */ // cbreak is what I want for my terminal Tetris. #include #include #include #include int main(int argc, char **argv) { struct termios ios = {0}; printf("TCGETS = 0x%x, struct termios is %zd bytes.\n", TCGETS, sizeof ios); if (ioctl(0, TCGETS, &ios)) { perror("TCGETS"); return 1; } printf("c_lflag of size %zd is at offset %zd with value 0x%x.\n", sizeof ios.c_lflag, (size_t)offsetof(struct termios, c_lflag), (int)ios.c_lflag); ios.c_lflag ^= ICANON; printf("ICANON is 0x%x. After flipping it c_lflag is 0x%x.\n", ICANON, ios.c_lflag); ios.c_lflag ^= ECHO; printf("ECHO is 0x%x. After flipping it c_lflag is 0x%x.\n", ECHO, ios.c_lflag); if (ioctl(0, TCSETS, &ios)) { perror("TCSETS"); return 1; } printf("TCSETS (0x%x) ran OK.\n", TCSETS); return 0; }