diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0627995 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +kilo diff --git a/Makefile b/Makefile index 5dbe62b..c9b5a5a 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,9 @@ kilo: kilo.c - $(CC) kilo.c -o kilo -Wall -Wextra -pedantic -std=c99 + mkdir -p ./out + $(CC) kilo.c -o ./out/kilo -Wall -Wextra -pedantic -std=c99 + +run: + ./out/kilo + +clean: + rm -rf ./out diff --git a/kilo b/kilo deleted file mode 100755 index 7058818..0000000 Binary files a/kilo and /dev/null differ diff --git a/kilo.c b/kilo.c index 3052f41..01b585d 100644 --- a/kilo.c +++ b/kilo.c @@ -1,8 +1,28 @@ +#include +#include #include -int main() { - char c; - while (read(STDIN_FILENO, &c, 1) == 1) - ; - return 0; +struct termios orig_termios; + +void disableRawMode() { + tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios); +} + +void enableRawMode() { + tcgetattr(STDIN_FILENO, &orig_termios); + atexit(disableRawMode); + + struct termios raw = orig_termios; + raw.c_lflag &= ~(ECHO); + raw.c_lflag &= ~(ICANON); + + tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); +} + +int main() { + enableRawMode(); + + char c; + while (read(STDIN_FILENO, &c, 1) == 1 && c != 'q'); + return 0; }