diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:55:52 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:55:52 -0600 |
| commit | 431855189a87388c323787d668e0698cbfefef30 (patch) | |
| tree | 6929c120151cd3d6c69f925b7c28a3220734dc51 | |
| parent | 5f8909cf7beeefa6318c795f8bf52b4b9f4361ae (diff) | |
| download | ztop-431855189a87388c323787d668e0698cbfefef30.tar.gz | |
Revert "tui: mouse messages; ztop: clickable tabs, wheel, better help"
This reverts commit 5f8909cf7beeefa6318c795f8bf52b4b9f4361ae.
| -rw-r--r-- | DESIGN.md | 5 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | src/ztop.c | 107 | ||||
| -rw-r--r-- | tui/tui.c | 54 | ||||
| -rw-r--r-- | tui/tui.h | 19 |
5 files changed, 22 insertions, 166 deletions
@@ -148,10 +148,7 @@ the terminal code out of the application and gives every view the same keys. The widgets are a viewport with its own selection and scroll offset, a table built from columns and a cell callback, tabs, a single line input, a progress bar and a status line; an application that wants no -tabs simply never draws them. The mouse is part of the message loop: SGR -mouse reporting (1006) turns a click into a `TUI_MSG_MOUSE` with 0-based -cells, and `tui_tabs_hit` answers which tab a column belongs to, so the -application decides what a click means. Commands and subscriptions are not modelled: +tabs simply never draws them. Commands and subscriptions are not modelled: a tick message and a return value saying "redraw" are enough here, and a `Cmd` type in C would be a function pointer by another name. @@ -77,13 +77,12 @@ prompt. There are three views, selected with `TAB`: | key | | | --- | --- | -| `TAB`, `Shift-TAB`, click a tab | next / previous view | +| `TAB`, `Shift-TAB` | next / previous view | | `1`..`4` | inside STORAGE: CSA, SQA, LSQA, private | | `p` | pause/resume refresh | | `r` | collect now | | `+`/`-` | refresh 1..60 s | | `j`/`k`, arrows, `PgUp`/`PgDn`, `g`/`G` | move and scroll the selected table | -| wheel, click a row | scroll, select a row | | `?` | help | | `q` | quit | @@ -448,8 +448,6 @@ static void draw_storage(struct tui *t, struct app *a) { tui_printf(t, 1, 4, t->w - 2, TUI_PLAIN, "used %s free %s mapped %s total %s use %s blocks %u", used, freed, mapped, total, pcbuf, v->blocks); - if (p >= 0) - tui_progress(t, t->w - 14, 4, 12, p); tui_table_draw(t, r, &a->storage, v->nsub, storage_cell, NULL, a); if (a->err[a->sub][0] != '\0') @@ -495,38 +493,27 @@ static void draw_jobs(struct tui *t, struct app *a) { } static void draw_help(struct tui *t) { - int w = t->w < 64 ? t->w - 2 : 62; - int h = 19; + int w = t->w < 56 ? t->w - 2 : 54; + int h = 16; int x = (t->w - w) / 2; int y = (t->h - h) / 2; - if (y < 0) - y = 0; tui_fill(t, x, y, w, h, ' ', TUI_PLAIN); tui_box(t, x, y, w, h, TUI_LABEL); tui_printf(t, x + 2, y + 1, w - 4, TUI_TITLE, "ztop keys"); - - tui_printf(t, x + 2, y + 3, w - 4, TUI_LABEL, "views"); - tui_printf(t, x + 2, y + 4, w - 4, TUI_PLAIN, - "TAB / Shift-TAB next / previous view"); + tui_printf(t, x + 2, y + 3, w - 4, TUI_PLAIN, "q quit"); + tui_printf(t, x + 2, y + 4, w - 4, TUI_PLAIN, "TAB next view"); tui_printf(t, x + 2, y + 5, w - 4, TUI_PLAIN, - "1 2 3 4 inside STORAGE: CSA SQA LSQA PVT"); - tui_printf(t, x + 2, y + 6, w - 4, TUI_PLAIN, - "click a tab same, with the mouse"); - - tui_printf(t, x + 2, y + 8, w - 4, TUI_LABEL, "moving"); - tui_printf(t, x + 2, y + 9, w - 4, TUI_PLAIN, "j k / arrows one row"); - tui_printf(t, x + 2, y + 10, w - 4, TUI_PLAIN, "PgUp PgDn a page"); - tui_printf(t, x + 2, y + 11, w - 4, TUI_PLAIN, - "g G / Home End first / last"); - tui_printf(t, x + 2, y + 12, w - 4, TUI_PLAIN, - "wheel, click scroll, select a row"); - - tui_printf(t, x + 2, y + 14, w - 4, TUI_LABEL, "the screen"); - tui_printf(t, x + 2, y + 15, w - 4, TUI_PLAIN, - "p pause r refresh now + - interval 1..60 s"); - tui_printf(t, x + 2, y + 16, w - 4, TUI_PLAIN, - "? close this help q quit"); + "1-3 storage, system, jobs"); + tui_printf(t, x + 2, y + 6, w - 4, TUI_PLAIN, "1-4 CSA, SQA, LSQA, PVT"); + tui_printf(t, x + 2, y + 7, w - 4, TUI_PLAIN, "p pause refresh"); + tui_printf(t, x + 2, y + 8, w - 4, TUI_PLAIN, "r refresh now"); + tui_printf(t, x + 2, y + 9, w - 4, TUI_PLAIN, "+ - interval up / down"); + tui_printf(t, x + 2, y + 10, w - 4, TUI_PLAIN, "j k move the selection"); + tui_printf(t, x + 2, y + 11, w - 4, TUI_PLAIN, "up dn same"); + tui_printf(t, x + 2, y + 12, w - 4, TUI_PLAIN, "g G first / last"); + tui_printf(t, x + 2, y + 13, w - 4, TUI_PLAIN, "? close help"); + tui_printf(t, x + 2, y + 14, w - 4, TUI_PLAIN, "1-4 inside storage"); } static void view(void *model, struct tui *t) { @@ -548,10 +535,7 @@ static void view(void *model, struct tui *t) { } if (a->help) draw_help(t); - tui_statusbar(t, - a->tab == 0 ? "TAB view 1-4 area j/k move wheel ? help" - : a->tab == 1 ? "TAB view r refresh ? help" - : "TAB view j/k move PgUp/PgDn ? help", + tui_statusbar(t, "q quit TAB view j/k move r refresh p pause ? help", a->paused ? "PAUSED" : ""); } @@ -593,65 +577,6 @@ static void usage(FILE *f) { " -h this text\n"); } -static void wheel(struct app *a, int dir, int height) { - if (a->tab == 0) - tui_viewport_move(&a->storage.vp, dir, a->info[a->sub].nsub, height); - else if (a->tab == 2) - tui_viewport_move(&a->jobs.vp, dir, a->sys.njobs, height); -} - -/** @brief Tabs, sub-tabs, table rows and the wheel. */ -static bool mouse_event(struct tui_app *app, const struct tui_msg *m) { - static const char *const views[3] = {"1 STORAGE", "2 SYSTEM", "3 JOBS"}; - struct app *a = app->model; - const struct tui_mouse *mo = &m->mouse; - int idx, row, height; - - height = (a->tab == 0 ? m->h - 8 : m->h - 6); - if (height < 1) - height = 1; - if (mo->button == 64 || mo->button == 65) { - wheel(a, mo->button == 64 ? -1 : 1, height); - return true; - } - if (mo->release || mo->button != 0) - return false; - if (mo->y == 1) { - idx = tui_tabs_hit(mo->x, views, 3); - if (idx < 0) - return false; - a->tab = idx; - return true; - } - if (a->tab == 0 && mo->y == 3) { - if (mo->x >= 1 && mo->x <= 5) - a->sub = 0; - else if (mo->x >= 7 && mo->x <= 11) - a->sub = 1; - else if (mo->x >= 13 && mo->x <= 18) - a->sub = 2; - else if (mo->x >= 20 && mo->x <= 24) - a->sub = 3; - else - return false; - return true; - } - if (a->tab == 0 && mo->y >= 6) { - row = a->storage.vp.top + (mo->y - 6); - if (row < a->info[a->sub].nsub) { - a->storage.vp.sel = row; - return true; - } - } else if (a->tab == 2 && mo->y >= 4) { - row = a->jobs.vp.top + (mo->y - 4); - if (row < a->sys.njobs) { - a->jobs.vp.sel = row; - return true; - } - } - return false; -} - static bool update(struct tui_app *app, const struct tui_msg *m) { struct app *a = app->model; int rows, height; @@ -669,8 +594,6 @@ static bool update(struct tui_app *app, const struct tui_msg *m) { } if (m->type == TUI_MSG_RESIZE) return true; - if (m->type == TUI_MSG_MOUSE) - return mouse_event(app, m); if (m->type != TUI_MSG_KEY) return false; @@ -24,10 +24,6 @@ #define ALT_ON ESCS "[?1049h" #define ALT_OFF ESCS "[?1049l" -/* 1000 reports button presses and releases, 1006 gives SGR coordinates - * (1-based, no 223 limit) so clicks beyond column 223 still work. */ -#define MOUSE_ON ESCS "[?1000h" ESCS "[?1006h" -#define MOUSE_OFF ESCS "[?1006l" ESCS "[?1000l" #define CUR_OFF ESCS "[?25l" #define CUR_ON ESCS "[?25h" #define CLEAR ESCS "[H" ESCS "[2J" @@ -53,8 +49,7 @@ static void wr(int fd, const void *buf, size_t n) { static void restore(struct tui *t) { if (!t->open) return; - wr(t->fd_out, RESET CUR_ON MOUSE_OFF ALT_OFF, - strlen(RESET CUR_ON MOUSE_OFF ALT_OFF)); + wr(t->fd_out, RESET CUR_ON ALT_OFF, strlen(RESET CUR_ON ALT_OFF)); (void)tcsetattr(t->fd_in, TCSANOW, &t->orig); } @@ -273,7 +268,7 @@ bool tui_open(struct tui *t) { #ifdef SIGWINCH (void)signal(SIGWINCH, on_winch); #endif - outs(t, ALT_ON CUR_OFF CLEAR MOUSE_ON); + outs(t, ALT_ON CUR_OFF CLEAR); out_flush(t); if (!tui_resize(t)) { restore(t); @@ -431,19 +426,6 @@ void tui_flush(struct tui *t) { out_flush(t); } -int tui_tabs_hit(int x, const char *const *labels, int n) { - int at = 0; - - for (int i = 0; i < n; i++) { - int len = (int)strlen(labels[i]) + 2; - - if (x >= at && x < at + len) - return i; - at += len + 1; - } - return -1; -} - int tui_tabs_draw(struct tui *t, int x, int y, const char *const *labels, int n, int active) { for (int i = 0; i < n; i++) { @@ -522,35 +504,6 @@ static int decode(struct tui *t) { shift_in(t, 3); return k; } - if (b[2] == '<') { - int v[3] = {0, 0, 0}; - int n = 0; - int i = 3; - - while (i < t->inlen && n < 3) { - if (b[i] >= '0' && b[i] <= '9') { - v[n] = v[n] * 10 + (b[i] - '0'); - i++; - } else if (b[i] == ';') { - n++; - i++; - } else { - break; - } - } - if (i >= t->inlen) - return TUI_KEY_NONE; /* wait for the final byte */ - if (b[i] != 'M' && b[i] != 'm') { - shift_in(t, i + 1); - return TUI_KEY_NONE; - } - t->mouse.button = v[0]; - t->mouse.x = v[1] > 0 ? v[1] - 1 : 0; - t->mouse.y = v[2] > 0 ? v[2] - 1 : 0; - t->mouse.release = b[i] == 'm'; - shift_in(t, i + 1); - return TUI_KEY_MOUSE; - } if (b[2] >= '1' && b[2] <= '9') { int v = 0, i = 2; while (i < t->inlen && b[i] >= '0' && b[i] <= '9') { @@ -667,9 +620,6 @@ void tui_run(struct tui *t, struct tui_app *app) { } else if (k == TUI_KEY_RESIZE) { (void)tui_resize(t); m.type = TUI_MSG_RESIZE; - } else if (k == TUI_KEY_MOUSE) { - m.type = TUI_MSG_MOUSE; - m.mouse = t->mouse; } else { m.type = TUI_MSG_KEY; m.key = k; @@ -66,19 +66,11 @@ enum { TUI_KEY_RESIZE, TUI_KEY_TAB, TUI_KEY_BACKTAB, - TUI_KEY_MOUSE, }; #define TUI_MAX_W 500 #define TUI_MAX_H 200 -/** @brief One mouse event; coordinates are 0-based cells. */ -struct tui_mouse { - int x, y; - int button; /**< 0 left, 1 middle, 2 right, 64 wheel up, 65 wheel down */ - bool release; -}; - struct tui { int w, h; int fd_in, fd_out; @@ -91,7 +83,6 @@ struct tui { int inlen; char out[32768]; int olen; - struct tui_mouse mouse; }; bool tui_alloc(struct tui *t, int w, int h); @@ -118,13 +109,12 @@ int tui_key(struct tui *t, int timeout_ms); /* ---- messages and the application loop ------------------------------- */ -enum tui_msg_type { TUI_MSG_KEY, TUI_MSG_RESIZE, TUI_MSG_TICK, TUI_MSG_MOUSE }; +enum tui_msg_type { TUI_MSG_KEY, TUI_MSG_RESIZE, TUI_MSG_TICK }; struct tui_msg { enum tui_msg_type type; - int key; /**< TUI_MSG_KEY: a byte or one of TUI_KEY_* */ - int w, h; /**< TUI_MSG_RESIZE: the new size */ - struct tui_mouse mouse; /**< TUI_MSG_MOUSE */ + int key; /**< TUI_MSG_KEY: a byte or one of TUI_KEY_* */ + int w, h; /**< TUI_MSG_RESIZE: the new size */ }; struct tui_app { @@ -183,9 +173,6 @@ bool tui_table_key(struct tui_table *tb, int key, int rows, int height); int tui_tabs_draw(struct tui *t, int x, int y, const char *const *labels, int n, int active); -/** @brief Which tab covers cell @p x, or -1. Tabs start at column 0. */ -int tui_tabs_hit(int x, const char *const *labels, int n); - /** Cycle tabs with left/right/tab/backtab; true when it was consumed. */ bool tui_tabs_key(int key, int *active, int n); |
