kilo.c 485 B

123456789101112131415161718192021222324252627
  1. #include <stdlib.h>
  2. #include <termios.h>
  3. #include <unistd.h>
  4. struct termios orig_termios;
  5. void disableRawMode() {
  6. tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
  7. }
  8. void enableRawMode() {
  9. tcgetattr(STDIN_FILENO, &orig_termios);
  10. atexit(disableRawMode);
  11. struct termios raw = orig_termios;
  12. raw.c_lflag &= ~(ECHO);
  13. tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
  14. }
  15. int main() {
  16. enableRawMode();
  17. char c;
  18. while (read(STDIN_FILENO, &c, 1) == 1 && c != 'q');
  19. return 0;
  20. }