summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 05:39:37 -0500
committerWormHeamer2026-01-02 05:39:37 -0500
commit436dfa22cc02da8727b4958ed3c9707e9bab2abc (patch)
tree8e629b17401edb2491c2f0d171d059e0a9438229
parent60acdc8fd0f046e6b7ec4bd4a584c10c294018d5 (diff)
get rid of needless LEDIT_UP and LEDIT_DOWN results
-rw-r--r--main.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/main.c b/main.c
index 21edaa4..a5b0dae 100644
--- a/main.c
+++ b/main.c
@@ -664,8 +664,6 @@ typedef enum {
LEDIT_EMPTY,
LEDIT_DONE,
LEDIT_CONT,
- LEDIT_UP,
- LEDIT_DOWN
} LineEditStatus;
static LineEditor line_editor(Str prompt, Arena *a) {
@@ -680,10 +678,6 @@ static LineEditStatus line_edit(LineEditor *le, u32 c) {
e.input_line = (Str) { 0, 0 };
e.input_prompt = (Str) { 0, 0 };
return LEDIT_DONE;
- case KEY_UP:
- return LEDIT_UP;
- case KEY_DOWN:
- return LEDIT_DOWN;
case KEY_ESC:
e.input_line = (Str) { 0, 0 };
e.input_prompt = (Str) { 0, 0 };
@@ -1280,6 +1274,11 @@ u32 sort_opt_idx(u32 *dest, Str *src, u32 n, Str pat, Arena *scratch) {
return scrn;
}
+
+static inline int umodi(int n, int d) {
+ return (d + n%d) % d;
+}
+
int select_opt(Str *optv, u32 optc, Str prompt) {
if (!optc) return -1;
e.optc = optc;
@@ -1293,15 +1292,31 @@ int select_opt(Str *optv, u32 optc, Str prompt) {
draw(NULL);
vui_blit();
e.scratch = s;
- LineEditStatus st = line_edit(&le, vui_key());
- if (st == LEDIT_EMPTY) break;
- if (st == LEDIT_DONE) {
- r = e.optvi[e.opti];
+ u32 c = vui_key();
+ switch (c) {
+ case KEY_DOWN:
+ e.opti = umodi(e.opti + 1, e.optc);
+ break;
+ case KEY_UP:
+ e.opti = umodi(e.opti - 1, e.optc);
+ break;
+ case KEY_PGDN:
+ e.opti = umodi(e.opti + LINES / 3, e.optc);
break;
+ case KEY_PGUP:
+ e.opti = umodi(e.opti - LINES / 3, e.optc);
+ break;
+ default: {
+ LineEditStatus st = line_edit(&le, c);
+ if (st == LEDIT_EMPTY) goto done;
+ if (st == LEDIT_DONE) {
+ r = e.optvi[e.opti];
+ goto done;
+ }
+ } break;
}
- if (st == LEDIT_DOWN) e.opti = (e.opti + 1) % e.optc;
- if (st == LEDIT_UP) e.opti = e.opti ? e.opti - 1 : e.optc - 1;
}
+done:
e.optc = 0;
e.optv = NULL;
return r;