From 2ca284619125af0d5c12e9210ff1bfc8f9122739 Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Wed, 23 Sep 2026 08:56:49 +0200 Subject: tui: one shared field editor, in-place form editing, value-only focus Forms edit fields in place in the value column instead of a bottom prompt, highlight only the focused value and scroll when taller than the screen; long text scrolls horizontally instead of wrapping. Fixes: typing after Backspace/Del no longer wipes the field, 'q' is text in row tables, the caret resets between cells, dialogs decode arrow keys, full buffers never take half a UTF-8 character, an invalid amount stays editable. Co-Authored-By: Claude Opus 5.5 --- clients/tui.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'clients/tui.h') diff --git a/clients/tui.h b/clients/tui.h index 1785a32..5ede574 100644 --- a/clients/tui.h +++ b/clients/tui.h @@ -99,7 +99,14 @@ int tui_field_edit(char *buf, size_t cap, size_t *pos, int ch, int *fresh); int tui_date_field_edit(char *buf, size_t cap, size_t *pos, int ch, int *fresh); -/* Line editor at (y,x) with the label already drawn. Returns 1 on Enter, +/* First byte to show so the caret at byte pos is visible in a field of + width columns (one column is kept for the caret after the last + character). `start` is the previous value: it is kept while the caret + stays visible, and moved back when removed text makes room. Pure. */ +size_t tui_field_scroll(const char *buf, size_t pos, int width, size_t start); + +/* Line editor at (y,x) up to the right border, scrolling horizontally, + with the label already drawn. Edits buf in place. Returns 1 on Enter, 2 on Tab, 3 on Shift-Tab, 0 on Esc. */ int tui_edit_field(int y, int x, char *buf, size_t cap, int mask); @@ -187,6 +194,8 @@ struct tui_form_field { }; int tui_form_next(int sel, int n, int ch); +/* First visible form line so line sl of nlines shows in view lines. Pure. */ +int tui_form_scroll(int top, int sl, int nlines, int view); int tui_form_run(const char *title, struct tui_form_field *f, int n, int can_edit, int *focus); @@ -283,6 +292,7 @@ struct tui_rt { int row, col; int fresh; size_t pos; + size_t hscroll; /* first byte shown in the focused cell */ void (*cell)(void *, int, int, char **, size_t *); void (*info)(void *, int, char *, size_t); void *ud; -- cgit v1.3