From c6bdbe16761f8286d1fa0283db9d78ec60be7650 Mon Sep 17 00:00:00 2001 From: SuperNovaa41 Date: Tue, 14 Jan 2025 21:49:46 -0500 Subject: [PATCH] progress on drawing the screen --- src/draw.c | 20 ++++++++++++++++++++ src/draw.h | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/draw.c b/src/draw.c index 01f8aaf..71050b0 100644 --- a/src/draw.c +++ b/src/draw.c @@ -12,8 +12,28 @@ extern screen_buffer_t screen_buffer; void refresh_screen(void) { + /** + * TODO: need to move the cursor back at the end + * also need to draw the cusor coords at the bottom + * and need to implement controls + */ + + int cur_x, cur_y; + + cur_x = editor.cx; + cur_y = editor.cy; + + // hide the cursor to prevent flickering + screen_buffer_append(&screen_buffer, HIDE_CURSOR_STR, HIDE_CURSOR_STR_LEN); + + screen_buffer_append(&screen_buffer, MOVE_CURSOR_HOME_STR, MOVE_CURSOR_HOME_STR_LEN); + + screen_buffer_append(&screen_buffer, CLEAR_SCREEN_STR, CLEAR_SCREEN_STR_LEN); + draw_editor_rows(); + screen_buffer_append(&screen_buffer, SHOW_CURSOR_STR, SHOW_CURSOR_STR_LEN); + write(STDOUT_FILENO, screen_buffer.text, screen_buffer.len); } diff --git a/src/draw.h b/src/draw.h index 365066c..9ae4577 100644 --- a/src/draw.h +++ b/src/draw.h @@ -1,6 +1,21 @@ #ifndef DRAW_H #define DRAW_H +/** BEGIN ASCII ESCAPE STRINGS **/ + +#define CLEAR_SCREEN_STR "\e[2J" +#define CLEAR_SCREEN_STR_LEN 4 + +#define MOVE_CURSOR_HOME_STR "\e[H" +#define MOVE_CURSOR_HOME_STR_LEN 3 + +#define HIDE_CURSOR_STR "\e[?25l" +#define HIDE_CURSOR_STR_LEN 6 +#define SHOW_CURSOR_STR "\e[?25h" +#define SHOW_CURSOR_STR_LEN 6 + +/** END ASCII ESCAPE STRINGS SECTION **/ + void refresh_screen(void); void draw_editor_rows(void);