diff --git a/main.c b/main.c index 0b4bc55..36cc31d 100644 --- a/main.c +++ b/main.c @@ -1063,6 +1063,7 @@ void draw(buffer* buf) { buffer_clear(buf); reposition_cursor(buf); draw_rows(buf); + hide_cursor(buf); buffer_write(buf); } @@ -1081,7 +1082,7 @@ bool process_keypress() { colorize(); } } else if (c == 'q') { - u_clear_screen(); + clear_screen_now(); return false; } return true; @@ -1118,7 +1119,7 @@ void update_window_size() { void handle_window_size_changed(int signal) { (void)signal; update_window_size(); - u_clear_screen(); + clear_screen_now(); } struct timespec subtract(struct timespec lhs, struct timespec rhs) { @@ -1163,7 +1164,7 @@ int main(int argc, char** argv) { sim_init(in); enable_raw_mode(); - u_clear_screen(); + clear_screen_now(); buffer buf = { 0, 0 }; draw(&buf); diff --git a/misc/terminal.c b/misc/terminal.c index f4bd59b..bac27f4 100644 --- a/misc/terminal.c +++ b/misc/terminal.c @@ -13,13 +13,11 @@ static struct termios g_orig_termios; static void write_stdin(const void* buf, ssize_t count) { - ssize_t res = write(STDIN_FILENO, buf, count); - if (res != count) { - exit(1); - } + int result = write(STDIN_FILENO, buf, count); + (void)result; // todo: handle EINTR } -void u_clear_screen() { +void clear_screen_now() { write_stdin("\x1b[2J", 4); // clear write_stdin("\x1b[H", 3); // reposition cursor } @@ -41,12 +39,12 @@ void show_cursor(buffer* buf) { buffer_append(buf, "\x1b[?25h", 6); } -void u_show_cursor() { +void show_cursor_now() { write_stdin("\x1b[?25h", 6); } void die(const char* msg) { - u_clear_screen(); + clear_screen_now(); perror(msg); exit(1); } @@ -59,7 +57,7 @@ void disable_raw_mode() { void enable_raw_mode() { atexit(disable_raw_mode); - atexit(u_show_cursor); + atexit(show_cursor_now); if (tcgetattr(STDIN_FILENO, &g_orig_termios) == -1) { die("failed to enable raw mode"); } diff --git a/misc/terminal.h b/misc/terminal.h index 4cefd4a..348718f 100644 --- a/misc/terminal.h +++ b/misc/terminal.h @@ -12,7 +12,7 @@ void buffer_clear(buffer* buf); void die(const char* msg); -void u_clear_screen(); +void clear_screen_now(); void clear_screen(buffer* buf); void reposition_cursor(buffer* buf);