From daf85f1cd65e941855f3f2cae4b1c3e675032898 Mon Sep 17 00:00:00 2001 From: Tasos Sahanidis Date: Mon, 28 Feb 2022 17:19:40 +0200 Subject: [PATCH] pw-top: Fix unicode character clipping Instead of using snprintf to clip the node line to the terminal width, causing multibyte characters to be split improperly, this lets curses wrap the text as it normally would, and then overwrites the wrapped text with the next line, simulating clipping. --- src/tools/pw-top.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/tools/pw-top.c b/src/tools/pw-top.c index 174642fc3..b91b110b2 100644 --- a/src/tools/pw-top.c +++ b/src/tools/pw-top.c @@ -241,9 +241,8 @@ static const char *print_perc(char *buf, size_t len, float val, float quantum) return buf; } -static void print_node(struct data *d, struct driver *i, struct node *n) +static void print_node(struct data *d, struct driver *i, struct node *n, int y) { - char line[1024]; char buf1[64]; char buf2[64]; char buf3[64]; @@ -264,7 +263,7 @@ static void print_node(struct data *d, struct driver *i, struct node *n) waiting = (n->measurement.awake - n->measurement.signal) / 1000000000.f, busy = (n->measurement.finish - n->measurement.awake) / 1000000000.f, - snprintf(line, sizeof(line), "%s %4.1u %6.1u %6.1u %s %s %s %s %3.1u %s%s", + mvwprintw(d->win, y, 0, "%s %4.1u %6.1u %6.1u %s %s %s %s %3.1u %s%s", n->measurement.status != 3 ? "!" : " ", n->id, frac.num, frac.denom, @@ -275,13 +274,12 @@ static void print_node(struct data *d, struct driver *i, struct node *n) i->xrun_count + n->errors, n->driver == n ? "" : " + ", n->name); - - wprintw(d->win, "%.*s\n", COLS-1, line); } static void do_refresh(struct data *d) { struct node *n, *t, *f; + int y = 1; wclear(d->win); wattron(d->win, A_REVERSE); @@ -293,15 +291,25 @@ static void do_refresh(struct data *d) if (n->driver != n) continue; - print_node(d, &n->info, n); + print_node(d, &n->info, n, y++); + if(y > LINES) + break; spa_list_for_each(f, &d->node_list, link) { if (f->driver != n || f == n) continue; - print_node(d, &n->info, f); + print_node(d, &n->info, f, y++); + if(y > LINES) + break; + } } + + // Clear from last line to the end of the window to hide text wrapping from the last node + wmove(d->win, y, 0); + wclrtobot(d->win); + wrefresh(d->win); }