Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Dec 13, 2022
1 parent 98ae3ed commit 81db526
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions kilo.c
Expand Up @@ -6,34 +6,36 @@

struct termios orig_termios;

void disableRawMode() {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
}
void disableRawMode() { tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios); }

void enableRawMode() {
tcgetattr(STDERR_FILENO, &orig_termios);
atexit(disableRawMode);

struct termios raw = orig_termios;
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
raw.c_oflag &= ~(OPOST);
raw.c_cflag |= ~(CS8);
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);

tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
tcgetattr(STDERR_FILENO, &orig_termios);
atexit(disableRawMode);

struct termios raw = orig_termios;
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
raw.c_oflag &= ~(OPOST);
raw.c_cflag |= ~(CS8);
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
raw.c_cc[VMIN] = 0;
raw.c_cc[VTIME] = 1;

tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}

int main() {
enableRawMode();

char c;
while (read(STDIN_FILENO, &c, 1) == 1 && c != 'q') {
if (iscntrl(c)) {
printf("%d\r\n", c);
} else {
printf("%d ('%c')\r\n", c, c);
}
enableRawMode();

while (1) {
char c = '\0';
read(STDIN_FILENO, &c, 1);
if (iscntrl(c)) {
printf("%d\r\n", c);
} else {
printf("%d ('%c')\r\n", c, c);
}
if (c == 'q') break;
}

return 0;
return 0;
}

0 comments on commit 81db526

Please sign in to comment.