From 2ded534ff74a3284741183c62d5e07d682dd600e Mon Sep 17 00:00:00 2001 From: Hadeed Ahmad Date: Thu, 24 Aug 2023 04:27:25 +0500 Subject: [PATCH] Just moved some lines around --- kilo.c | 80 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/kilo.c b/kilo.c index 05dca6d..9308feb 100644 --- a/kilo.c +++ b/kilo.c @@ -1,29 +1,36 @@ -#include #include #include #include #include #include +void enable_raw_mode(); +void disable_raw_mode(); + +void editor_redraw_screen(); +void editor_clear_screen(); +void editor_draw_rows(); +void editor_process_key(); + +void die(const char *s); + #define CTRL_KEY(key) ((key) & 0x1f) struct termios orig_termios; -void editor_clear_screen() { - write(STDIN_FILENO, "\x1b[2J", 4); - write(STDIN_FILENO, "\x1b[H", 3); -} +int main() { + if (!isatty(STDIN_FILENO)) { + printf("kilo only supports a terminal at standard in. Exiting."); + exit(1); + } -void die(const char *s) { - editor_clear_screen(); + enable_raw_mode(); + while (1) { + editor_redraw_screen(); + editor_process_key(); + } - perror(s); - exit(1); -} - -void disable_raw_mode() { - if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1) - die("tcsetattr"); + return 0; } void enable_raw_mode() { @@ -36,20 +43,9 @@ void enable_raw_mode() { if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) == -1) die("tcsetattr"); } -char editor_read_key() { - char c = '\0'; - - while (c == '\0') - read(STDIN_FILENO, &c, 1); - - return c; -} - -void editor_draw_rows() { - int rows = 24; - for (int y = 0; y < rows - 1; y++) - write(STDIN_FILENO, "~\r\n", 3); - write(STDIN_FILENO, "~", 1); +void disable_raw_mode() { + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1) + die("tcsetattr"); } void editor_redraw_screen() { @@ -60,6 +56,18 @@ void editor_redraw_screen() { write(STDIN_FILENO, "\x1b[H", 3); } +void editor_clear_screen() { + write(STDIN_FILENO, "\x1b[2J", 4); + write(STDIN_FILENO, "\x1b[H", 3); +} + +void editor_draw_rows() { + int rows = 24; + for (int y = 0; y < rows - 1; y++) + write(STDIN_FILENO, "~\r\n", 3); + write(STDIN_FILENO, "~", 1); +} + void editor_process_key() { char c; read(STDIN_FILENO, &c, 1); @@ -75,17 +83,9 @@ void editor_process_key() { } } -int main() { - if (!isatty(STDIN_FILENO)) { - printf("kilo only supports a terminal at standard in. Exiting."); - exit(1); - } +void die(const char *s) { + editor_clear_screen(); - enable_raw_mode(); - while (1) { - editor_redraw_screen(); - editor_process_key(); - } - - return 0; + perror(s); + exit(1); }