From da73d0c5421644e5c807d93cef12fd77a3239e8b Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 29 Jan 2022 16:55:12 -0600 Subject: [PATCH] Top: move sort change to SHIFT LEFT/RIGHT, and make LEFT/RIGHT move list. (It's actually skipping X many fields at the start, up to showing just the last field across the whole screen. I could continue into indent to show more of the last field, but probably need to add a way to freeze updates first.) --- toys/posix/ps.c | 51 ++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 35bfbf45..48a065a8 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -106,8 +106,8 @@ config TOP -u Show these USERs -q Quiet (no header lines) - Cursor LEFT/RIGHT to change sort, UP/DOWN move list, space to force - update, R to reverse sort, Q to exit. + Cursor UP/DOWN or LEFT/RIGHT to move list, SHIFT LEFT/RIGHT to change sort, + space to force update, R to reverse sort, Q to exit. # Requires CONFIG_IRQ_TIME_ACCOUNTING in the kernel for /proc/$$/io config IOTOP @@ -210,7 +210,7 @@ GLOBALS( struct ptr_len gg, GG, pp, PP, ss, tt, uu, UU; struct dirtree *threadparent; - unsigned width, height; + unsigned width, height, scroll; dev_t tty; void *fields, *kfields; long long ticks, bits, time; @@ -638,11 +638,14 @@ static char *string_field(struct procpid *tb, struct ofields *field) static void show_ps(void *p) { struct procpid *tb = p; - struct ofields *field; - int pad, len, width = TT.width, abslen, sign, olen, extra = 0; + struct ofields *field = TT.fields; + int pad, len, width = TT.width, abslen, sign, olen, scroll, extra = 0; + + // Skip TT.scroll many fields (but not last one) + for (scroll = TT.scroll; scroll && field->next; scroll--) field = field->next; // Loop through fields to display - for (field = TT.fields; field; field = field->next) { + for (; field; field = field->next) { char *out = string_field(tb, field); // Output the field, appropriately padded @@ -1125,7 +1128,10 @@ static char *parse_ko(void *data, char *type, int length) static long long get_headers(struct ofields *field, char *buf, int blen) { long long bits = 0; - int len = 0; + int len = 0, scroll; + + // Skip TT.scroll many fields (but not last one) + for (scroll = TT.scroll; scroll && field->next; scroll--) field = field->next; for (; field; field = field->next) { len += snprintf(buf+len, blen-len, " %*s"+!bits, field->len, @@ -1636,6 +1642,7 @@ static void top_common( pos += sprintf(pos, "% *lld%%%s", j, (ll+5)/10, cpufields[i]); } lines = header_line(lines, 0); + // Display "iotop" header. } else { struct ofields *field; struct procpid tb; @@ -1672,9 +1679,7 @@ static void top_common( *pos = 0; lines = header_line(lines, 1); } - if (!recalc && !FLAG(b)) - printf("\e[%dH\e[J", 1+TT.height-lines); - recalc = 1; + if (!recalc && !FLAG(b)) printf("\e[%dH\e[J", 1+TT.height-lines); for (i = 0; ireverse *= -1; else { i -= 256; - if (i == KEY_LEFT) setsort(TT.sortpos-1); - else if (i == KEY_RIGHT) setsort(TT.sortpos+1); - // KEY_UP is 0, so at end of strchr - else if (strchr((char []){KEY_DOWN,KEY_PGUP,KEY_PGDN,KEY_UP}, i)) { - recalc = 0; - - if (i == KEY_UP) topoff--; - else if (i == KEY_DOWN) topoff++; - else if (i == KEY_PGDN) topoff += lines; - else if (i == KEY_PGUP) topoff -= lines; - if (topoff<0) topoff = 0; - if (topoff>mix.count) topoff = mix.count; - } + if (i == (KEY_SHIFT|KEY_LEFT)) setsort(TT.sortpos-1); + else if (i == (KEY_SHIFT|KEY_RIGHT)) setsort(TT.sortpos+1); + else if (i == KEY_RIGHT) TT.scroll++; + else if (i == KEY_LEFT && TT.scroll) TT.scroll--; + else if (recalc-- && i == KEY_UP) topoff--; + else if (i == KEY_DOWN) topoff++; + else if (i == KEY_PGDN) topoff += lines; + else if (i == KEY_PGUP) topoff -= lines; + else continue; + if (topoff<0) topoff = 0; + if (topoff>mix.count) topoff = mix.count; } - continue; } free(mix.tb); -- 2.39.2