From: Max Kellermann Date: Fri, 9 Oct 2009 19:24:00 +0000 (+0200) Subject: list_window: fix narrow cursor drawing X-Git-Tag: release-0.16~155 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=dde5f9a0b66a5539dfa8b1d9b9069801d6c2c6a1;p=ncmpc.git list_window: fix narrow cursor drawing When there's a second column (e.g. in the playlist screen), the space between the two columns isn't cleared properly, because the cursor position was changed by the second column renderer. Side effect of this patch: space drawing is a little bit optimized, because it won't clear the second column (in wide-cursor mode) only to draw the second column text on top of it. --- diff --git a/NEWS b/NEWS index 690f354..d63ab45 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ ncmpc 0.16 - not yet released * search: eliminate duplicate results * use the "idle" command to reduce CPU and network usage * disable the status bar clock by default +* list_window: fix narrow cursor drawing ncmpc 0.15 - 2009-09-24 diff --git a/src/list_window.c b/src/list_window.c index 9278bdd..3faf437 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -299,6 +299,16 @@ list_window_paint_row(WINDOW *w, unsigned y, unsigned width, const char *text, const char *second_column) { unsigned text_width = utf8_width(text); + unsigned second_column_width; + + if (second_column != NULL) { + second_column_width = utf8_width(second_column) + 1; + if (second_column_width < width) + width -= second_column_width; + else + second_column_width = 0; + } else + second_column_width = 0; if (highlight) colors_use(w, COLOR_LIST_BOLD); @@ -312,20 +322,25 @@ list_window_paint_row(WINDOW *w, unsigned y, unsigned width, if (options.wide_cursor && text_width < width) whline(w, ' ', width - text_width); - if (second_column != NULL) { - unsigned second_column_width = utf8_width(second_column) + 1; - if (width > second_column_width) { - wmove(w, y, width - second_column_width); - waddch(w, ' '); - waddstr(w, second_column); - } + if (second_column_width > 0) { + wmove(w, y, width); + waddch(w, ' '); + waddstr(w, second_column); } if (selected) wattroff(w, A_REVERSE); - if (!options.wide_cursor && text_width < width) - wclrtoeol(w); + if (!options.wide_cursor && text_width < width) { + if (second_column_width == 0) + /* the cursor is at the end of the text; clear + the rest of this row */ + wclrtoeol(w); + else + /* there's a second column: clear the space + between the first and the second column */ + mvwhline(w, y, text_width, ' ', width - text_width); + } } void