From 520c83cbbf5a0a6871d09ed7df9b0628efbd5576 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 28 Apr 2020 11:00:14 -0700 Subject: [PATCH] Make screen_reset_mode_t an enum class instead of an enum Improves type safety. --- src/reader.cpp | 12 ++++++------ src/screen.cpp | 12 ++++++------ src/screen.h | 10 +++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 328d10944..1a29e8f87 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -957,7 +957,7 @@ void reader_data_t::repaint_if_needed() { if (needs_reset) { exec_prompt(); - s_reset(&screen, screen_reset_current_line_and_prompt); + s_reset(&screen, screen_reset_mode_t::current_line_and_prompt); screen_reset_needed = false; } @@ -2313,7 +2313,7 @@ void reader_pop() { reader_interactive_destroy(); } else { s_end_current_loop = false; - s_reset(&new_reader->screen, screen_reset_abandon_line); + s_reset(&new_reader->screen, screen_reset_mode_t::abandon_line); } } @@ -2652,7 +2652,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat // elsewhere, we detect if the mode output is empty. exec_mode_prompt(); if (!mode_prompt_buff.empty()) { - s_reset(&screen, screen_reset_current_line_and_prompt); + s_reset(&screen, screen_reset_mode_t::current_line_and_prompt); screen_reset_needed = false; repaint(); break; @@ -2665,7 +2665,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat if (!rls.coalescing_repaints) { rls.coalescing_repaints = true; exec_prompt(); - s_reset(&screen, screen_reset_current_line_and_prompt); + s_reset(&screen, screen_reset_mode_t::current_line_and_prompt); screen_reset_needed = false; repaint(); } @@ -2948,7 +2948,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat // already be printed, all we need to do is repaint. wcstring_list_t argv(1, el->text()); event_fire_generic(parser(), L"fish_posterror", &argv); - s_reset(&screen, screen_reset_abandon_line); + s_reset(&screen, screen_reset_mode_t::abandon_line); mark_repaint_needed(); } @@ -3468,7 +3468,7 @@ maybe_t reader_data_t::readline(int nchars_or_0) { history_search.reset(); - s_reset(&screen, screen_reset_abandon_line); + s_reset(&screen, screen_reset_mode_t::abandon_line); event_fire_generic(parser(), L"fish_prompt"); exec_prompt(); diff --git a/src/screen.cpp b/src/screen.cpp index 8a5ee83d4..4ff2f14a1 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -378,7 +378,7 @@ static void s_check_status(screen_t *s) { // modeled cursor y-pos to its earlier value. int prev_line = s->actual.cursor.y; write_loop(STDOUT_FILENO, "\r", 1); - s_reset(s, screen_reset_current_line_and_prompt); + s_reset(s, screen_reset_mode_t::current_line_and_prompt); s->actual.cursor.y = prev_line; } } @@ -631,7 +631,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring if (scr->actual_width != SCREEN_WIDTH_UNINITIALIZED) { need_clear_screen = true; s_move(scr, 0, 0); - s_reset(scr, screen_reset_current_line_contents); + s_reset(scr, screen_reset_mode_t::current_line_contents); need_clear_lines = need_clear_lines || scr->need_clear_lines; need_clear_screen = need_clear_screen || scr->need_clear_screen; @@ -1093,19 +1093,19 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) { bool abandon_line = false, repaint_prompt = false, clear_to_eos = false; switch (mode) { - case screen_reset_current_line_contents: { + case screen_reset_mode_t::current_line_contents: { break; } - case screen_reset_current_line_and_prompt: { + case screen_reset_mode_t::current_line_and_prompt: { repaint_prompt = true; break; } - case screen_reset_abandon_line: { + case screen_reset_mode_t::abandon_line: { abandon_line = true; repaint_prompt = true; break; } - case screen_reset_abandon_line_and_clear_to_end_of_screen: { + case screen_reset_mode_t::abandon_line_and_clear_to_end_of_screen: { abandon_line = true; repaint_prompt = true; clear_to_eos = true; diff --git a/src/screen.h b/src/screen.h index 0394845ef..2927f3432 100644 --- a/src/screen.h +++ b/src/screen.h @@ -193,15 +193,15 @@ void s_reset(screen_t *s, bool reset_cursor, bool reset_prompt = true); /// Stat stdout and stderr and save result as the current timestamp. void s_save_status(screen_t *s); -enum screen_reset_mode_t { +enum class screen_reset_mode_t { /// Do not make a new line, do not repaint the prompt. - screen_reset_current_line_contents, + current_line_contents, /// Do not make a new line, do repaint the prompt. - screen_reset_current_line_and_prompt, + current_line_and_prompt, /// Abandon the current line, go to the next one, repaint the prompt. - screen_reset_abandon_line, + abandon_line, /// Abandon the current line, go to the next one, clear the rest of the screen. - screen_reset_abandon_line_and_clear_to_end_of_screen + abandon_line_and_clear_to_end_of_screen }; void s_reset(screen_t *s, screen_reset_mode_t mode);