From 43db0ce7df9846946d358bc009165f9877f427f9 Mon Sep 17 00:00:00 2001 From: anon Date: Sat, 17 Aug 2024 01:15:06 +0200 Subject: [PATCH] flashing drastically descreased --- documentation/TODO.md | 3 +-- source/main.c | 4 ++-- source/tui.c | 34 +++++++++++++++++++++++----------- source/tui.h | 1 + 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/documentation/TODO.md b/documentation/TODO.md index 2647cb8..44f9a2b 100644 --- a/documentation/TODO.md +++ b/documentation/TODO.md @@ -1,3 +1,2 @@ -+ scroll flashes -+ technical dept in tui.cpp - + resizing ++ unicode support in the tui diff --git a/source/main.c b/source/main.c index 23dcc73..168ecbb 100644 --- a/source/main.c +++ b/source/main.c @@ -86,8 +86,8 @@ signed main(const int argc, const char * const * const argv) { pthread_t query_thread; pthread_create(&query_thread, NULL, async_input, NULL); while (do_run) { - loop_start: entry_t entry; + loop_start: if (do_redisplay) { do_redisplay = false; if (is_input_changed) { @@ -97,7 +97,7 @@ signed main(const int argc, const char * const * const argv) { requery(); } while (entry = get_entry(), entry.command != NULL) { - if (is_input_changed) { goto loop_start; } + if (is_input_changed) { tui_rearm(); goto loop_start; } tui_append_back(entry); } tui_refresh(); diff --git a/source/tui.c b/source/tui.c index 83b3249..cb78266 100644 --- a/source/tui.c +++ b/source/tui.c @@ -39,7 +39,7 @@ static int input_available = false; static int input; // -static void refresh_input(void); +static inline void update_input(void); static void full_redraw(void); static bool do_fullredraw = true; @@ -73,7 +73,13 @@ int init_tui(void) { int return_input_available(void) { return input_available; } rl_getc_function = getc_function; rl_input_available_hook = return_input_available; - rl_redisplay_function = refresh_input; + /* Due to this bug: https://mail.gnu.org/archive/html/bug-readline/2013-09/msg00021.html ; + * we cannot null this function. + * Im seriously questioning why readline is still the """default""" library in the wild + * and whether i should participate. + */ + int redisplay_nop(void) { return; } + rl_redisplay_function = redisplay_nop; /* We must specify an input handler or readline chimps out, * but we dont want the line to be actually submittable, * (search is continous and that would delete what the user @@ -131,19 +137,25 @@ void full_redraw(void) { box(main_window, 0, 0); waddstr(version_window, version_string); - wrefresh(version_window); - refresh_input(); + update_input(); + + wnoutrefresh(version_window); + doupdate(); } -static -void refresh_input(void) { +void tui_rearm() { + entry_line_index = 0; +} + +static inline +void update_input() { wmove(input_window, 0, 0); wclrtoeol(input_window); waddstr(input_window, "$ "); waddstr(input_window, rl_line_buffer); waddch(input_window, ACS_BLOCK); - wrefresh(input_window); + wnoutrefresh(input_window); } void tui_refresh(void) { @@ -160,11 +172,11 @@ void tui_refresh(void) { } entry_line_index = 0; - refresh_input(); + update_input(); - wrefresh(entry_window); - wmove(entry_window, 0, 0); - wrefresh(main_window); + wnoutrefresh(entry_window); + wnoutrefresh(main_window); + doupdate(); } diff --git a/source/tui.h b/source/tui.h index 149552e..cc02029 100644 --- a/source/tui.h +++ b/source/tui.h @@ -19,6 +19,7 @@ extern int deinit_tui(void); extern void tui_append_back(const entry_t entry); extern void tui_refresh(void); +extern void tui_rearm(void); extern void tui_take_input(void);