Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Dec 11, 2022
1 parent 1e275b2 commit edb6a9d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions kilo.c
@@ -1,3 +1,38 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>

struct termios 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 &= ~(ICRNL | IXON);
raw.c_oflag &= ~(OPOST);
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);

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);
}
}

return 0;
}

0 comments on commit edb6a9d

Please sign in to comment.