From 160fb1cfffde73e55c131e8364b2f88a06a6767d Mon Sep 17 00:00:00 2001 From: trilader Date: Thu, 26 Nov 2020 13:25:25 +0100 Subject: [PATCH] Add C-l to force repaint --- main.cpp | 5 ++++- tui.cpp | 20 +++++++++++++++----- tui.h | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 7656924..7a27099 100644 --- a/main.cpp +++ b/main.cpp @@ -435,6 +435,7 @@ int main() select_channel_by_index(0); bool exit = false; + bool force_repaint = false; std::vector actions = { {TERMPAINT_EV_CHAR, "a", 0, action_add_channel_by_name, "Add channel by name"}, {TERMPAINT_EV_CHAR, "A", 0, action_add_channel_by_id, "Add channel by Id"}, @@ -458,6 +459,7 @@ int main() {TERMPAINT_EV_KEY, "End", 0, action_select_last_video, "Last video"}, {TERMPAINT_EV_KEY, "ArrowLeft", 0, action_scroll_title_left, "Scroll title left"}, {TERMPAINT_EV_KEY, "ArrowRight", 0, action_scroll_title_right, "Scroll title right"}, + {TERMPAINT_EV_CHAR, "l", TERMPAINT_MOD_CTRL, [&](){ force_repaint = true; }, "Force redraw"}, }; do { @@ -466,7 +468,8 @@ int main() draw_channel_list(videos[channels.at(*selected_channel).id]); else draw_no_channels_msg(); - tp_flush(); + tp_flush(force_repaint); + force_repaint = false; auto event = tp_wait_for_event(); if(!event) diff --git a/tui.cpp b/tui.cpp index f36f887..502c199 100644 --- a/tui.cpp +++ b/tui.cpp @@ -105,9 +105,9 @@ void tp_shutdown() termpaint_terminal_free_with_restore(terminal); } -void tp_flush() +void tp_flush(const bool force) { - termpaint_terminal_flush(terminal, false); + termpaint_terminal_flush(terminal, force); } std::optional tp_wait_for_event() @@ -202,12 +202,14 @@ int get_selection(const std::string &caption, const std::vector &en const int rows_needed = entries.size()+2; // Number of entries and top/bottom border bool done = false; + bool force_repaint = false; std::vector actions = { {TERMPAINT_EV_KEY, "ArrowUp", 0, [&](){ if(selected > 0) selected--; }, "Previous option"}, {TERMPAINT_EV_KEY, "ArrowDown", 0, [&](){ if(selected < entries.size() - 1) selected++; }, "Next option"}, {TERMPAINT_EV_KEY, "Escape", 0, [&](){ selected = -1; done = true; }, "Abort selection"}, {TERMPAINT_EV_KEY, "Enter", 0, [&](){ done = true; }, "Confirm selection"}, {EV_IGNORE, "1..9", 0, nullptr, "Select option 1..9"}, + {TERMPAINT_EV_CHAR, "l", TERMPAINT_MOD_CTRL, [&](){ force_repaint = true; }, "Force redraw"}, }; while (!done) { @@ -227,7 +229,8 @@ int get_selection(const std::string &caption, const std::vector &en termpaint_surface_write_with_attr(surface, x+2, yy++, e.c_str(), attr); cur_entry++; } - termpaint_terminal_flush(terminal, false); + termpaint_terminal_flush(terminal, force_repaint); + force_repaint = false; auto event = wait_for_event(integration, 0); if(!event) @@ -285,6 +288,7 @@ std::string get_string(const std::string &caption, const std::string &text, cons termpaint_terminal_set_cursor_style(terminal, TERMPAINT_CURSOR_STYLE_BAR, true); bool done = false; + bool force_repaint = false; std::vector actions = { {TERMPAINT_EV_KEY, "Home", 0, [&](){ input_pos = 0; }, "Go to beginning of input"}, {TERMPAINT_EV_CHAR, "a", TERMPAINT_MOD_CTRL, [&](){ input_pos = 0; }, "Go to beginning of input"}, @@ -299,6 +303,7 @@ std::string get_string(const std::string &caption, const std::string &text, cons {TERMPAINT_EV_KEY, "Escape", 0, [&](){ input.clear(); done = true; }, "Abort input"}, {TERMPAINT_EV_KEY, "Enter", 0, [&](){ done = true; }, "Confirm input"}, + {TERMPAINT_EV_CHAR, "l", TERMPAINT_MOD_CTRL, [&](){ force_repaint = true; }, "Force redraw"}, }; while(!done) { @@ -308,7 +313,8 @@ std::string get_string(const std::string &caption, const std::string &text, cons termpaint_surface_write_with_attr(surface, x + 1, input_row, input.c_str(), attributes[ASNormal].normal); termpaint_terminal_set_cursor_position(terminal, x + 1 + input_pos, input_row); - termpaint_terminal_flush(terminal, false); + termpaint_terminal_flush(terminal, force_repaint); + force_repaint = false; auto event = wait_for_event(integration, 0); if(!event) @@ -389,16 +395,19 @@ Button message_box(const std::string &caption, const std::string &text, const Bu const size_t cols_needed = width + 4; bool done = false; + bool force_repaint = false; std::vector actions; if(active_buttons.size() > 1) { actions = { {TERMPAINT_EV_KEY, "Enter", 0, [&](){ done = true; }, "Confirm Selection"}, {TERMPAINT_EV_KEY, "ArrowLeft", 0, [&](){ if(selected_button > 0) selected_button--;}, "Previous option"}, {TERMPAINT_EV_KEY, "ArrowRight", 0, [&](){ if(selected_button < active_buttons.size() - 1) selected_button++; }, "Next option"}, + {TERMPAINT_EV_CHAR, "l", TERMPAINT_MOD_CTRL, [&](){ force_repaint = true; }, "Force redraw"}, }; } else { actions = { {TERMPAINT_EV_KEY, "Enter", 0, [&](){ done = true; }, "Close dialog"}, + {TERMPAINT_EV_CHAR, "l", TERMPAINT_MOD_CTRL, [&](){ force_repaint = true; }, "Force redraw"}, }; } @@ -427,7 +436,8 @@ Button message_box(const std::string &caption, const std::string &text, const Bu button_x += active_buttons[btn].width + 2 + 1; } - termpaint_terminal_flush(terminal, false); + termpaint_terminal_flush(terminal, force_repaint); + force_repaint = false; auto event = wait_for_event(integration, 0); if(!event) diff --git a/tui.h b/tui.h index 621dbe0..391fbb0 100644 --- a/tui.h +++ b/tui.h @@ -54,7 +54,7 @@ Button operator&(const Button &a, const Button &b); void tp_init(); void tp_shutdown(); -void tp_flush(); +void tp_flush(const bool force=false); void tp_pause(); void tp_unpause(); std::optional tp_wait_for_event();