hirc

IRC client
Log | Files | Refs

commit 3670e6e98a528d7f9c93cfb8a2628f9bd7d752de
parent 68e4ee7efa92da16a70eb36762e7d07c594828f8
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 31 Oct 2021 22:42:45 +0000

ui.c hirc.h: implement flicker-free window clearing

Diffstat:
Mhirc.h | 2++
Mui.c | 38+++++++++++++++++++++++++++++---------
2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/hirc.h b/hirc.h @@ -103,6 +103,8 @@ int ui_get_pair(short fg, short bg); int ui_wprintc(struct Window *window, int lines, char *format, ...); int ui_strlenc(struct Window *window, char *s, int *lines); void ui_select(struct Server *server, struct Channel *channel); +void ui_filltoeol(struct Window *window, char c); +void ui_wclear(struct Window *window); void ui_error_(char *file, int line, char *format, ...); #define ui_error(format, ...) ui_error_(__FILE__, __LINE__, format, __VA_ARGS__); void ui_perror_(char *file, int line, char *str); diff --git a/ui.c b/ui.c @@ -251,10 +251,7 @@ ui_draw_input(void) { int offset; int x; - wmove(windows[Win_input].window, 0, 0); - for (x = 0; x < windows[Win_input].w; x++) - waddch(windows[Win_input].window, ' '); - wmove(windows[Win_input].window, 0, 0); + ui_wclear(&windows[Win_input]); /* Round input.counter down to the nearest windows[Win_input].w. * This gives "pages" that are each as long as the width of the input window */ @@ -273,8 +270,10 @@ ui_draw_input(void) { void ui_draw_nicklist(void) { struct Nick *p; + int y; + + ui_wclear(&windows[Win_nicklist]); - wclear(windows[Win_nicklist].window); if (!selected.channel || !windows[Win_nicklist].location) return; @@ -342,9 +341,10 @@ ui_draw_buflist(void) { struct Server *sp; struct Channel *chp; int i = 1, len, tmp; - int sc, cc; + int sc, cc, y; + + ui_wclear(&windows[Win_buflist]); - wclear(windows[Win_buflist].window); if (!windows[Win_buflist].location) return; @@ -552,12 +552,32 @@ ui_strlenc(struct Window *window, char *s, int *lines) { } void +ui_filltoeol(struct Window *window, char c) { + int y, x; + + getyx(window->window, y, x); + for (; x < window->w; x++) + waddch(window->window, c); +} + +void +ui_wclear(struct Window *window) { + int y; + + for (y = 0; y <= window->h; y++) { + wmove(window->window, y, 0); + ui_filltoeol(window, ' '); + } + wmove(window->window, 0, 0); +} + +void ui_draw_main(void) { struct History *p; int y, lines; - /* need to do manual clearing to avoid the flicker */ - wclear(windows[Win_main].window); + ui_wclear(&windows[Win_main]); + y = windows[Win_main].h; for (p = selected.history->history; p && y > 0; p = p->next) { ui_strlenc(&windows[Win_main], p->raw, &lines);