Generation

generate functionThu, 19 Jan 2023

using termios, turn terminal to non-canonical mode, and turn off echo

#include <stdio.h> #include <stdlib.h> #include <termios.h> #include <unistd.h> struct termios orig_termios; void disable_raw_mode(){ tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios); } void enable_raw_mode(){ tcgetattr(STDIN_FILENO, &orig_termios); atexit(disable_raw_mode); struct termios raw = orig_termios; raw.c_lflag &= ~(ECHO | ICANON); tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); } int main(){ enable_raw_mode(); char c; while(read(STDIN_FILENO, &c, 1) == 1 && c != 'q'); return 0; }

Want to kickstart your project?Use the new AI Studio to create your code