Make screen_reset_mode_t an enum class instead of an enum

Improves type safety.
This commit is contained in:
ridiculousfish 2020-04-28 11:00:14 -07:00
parent 844ae48dc0
commit 520c83cbbf
3 changed files with 17 additions and 17 deletions

View File

@ -957,7 +957,7 @@ void reader_data_t::repaint_if_needed() {
if (needs_reset) { if (needs_reset) {
exec_prompt(); 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; screen_reset_needed = false;
} }
@ -2313,7 +2313,7 @@ void reader_pop() {
reader_interactive_destroy(); reader_interactive_destroy();
} else { } else {
s_end_current_loop = false; 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. // elsewhere, we detect if the mode output is empty.
exec_mode_prompt(); exec_mode_prompt();
if (!mode_prompt_buff.empty()) { 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; screen_reset_needed = false;
repaint(); repaint();
break; break;
@ -2665,7 +2665,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
if (!rls.coalescing_repaints) { if (!rls.coalescing_repaints) {
rls.coalescing_repaints = true; rls.coalescing_repaints = true;
exec_prompt(); 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; screen_reset_needed = false;
repaint(); 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. // already be printed, all we need to do is repaint.
wcstring_list_t argv(1, el->text()); wcstring_list_t argv(1, el->text());
event_fire_generic(parser(), L"fish_posterror", &argv); 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(); mark_repaint_needed();
} }
@ -3468,7 +3468,7 @@ maybe_t<wcstring> reader_data_t::readline(int nchars_or_0) {
history_search.reset(); 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"); event_fire_generic(parser(), L"fish_prompt");
exec_prompt(); exec_prompt();

View File

@ -378,7 +378,7 @@ static void s_check_status(screen_t *s) {
// modeled cursor y-pos to its earlier value. // modeled cursor y-pos to its earlier value.
int prev_line = s->actual.cursor.y; int prev_line = s->actual.cursor.y;
write_loop(STDOUT_FILENO, "\r", 1); 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; 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) { if (scr->actual_width != SCREEN_WIDTH_UNINITIALIZED) {
need_clear_screen = true; need_clear_screen = true;
s_move(scr, 0, 0); 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_lines = need_clear_lines || scr->need_clear_lines;
need_clear_screen = need_clear_screen || scr->need_clear_screen; 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; bool abandon_line = false, repaint_prompt = false, clear_to_eos = false;
switch (mode) { switch (mode) {
case screen_reset_current_line_contents: { case screen_reset_mode_t::current_line_contents: {
break; break;
} }
case screen_reset_current_line_and_prompt: { case screen_reset_mode_t::current_line_and_prompt: {
repaint_prompt = true; repaint_prompt = true;
break; break;
} }
case screen_reset_abandon_line: { case screen_reset_mode_t::abandon_line: {
abandon_line = true; abandon_line = true;
repaint_prompt = true; repaint_prompt = true;
break; 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; abandon_line = true;
repaint_prompt = true; repaint_prompt = true;
clear_to_eos = true; clear_to_eos = true;

View File

@ -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. /// Stat stdout and stderr and save result as the current timestamp.
void s_save_status(screen_t *s); 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. /// 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. /// 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. /// 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. /// 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); void s_reset(screen_t *s, screen_reset_mode_t mode);