From 9155d10d6ff87ff5eca1e481e45f7d55cac86e0a Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Sun, 25 Oct 2026 15:53:51 +0300 Subject: [PATCH] tui: folders, discord and webhooks keep names, previews and errors whole at 100x24 and 80x24 Signed-off-by: dawn <90008@klbr.net> --- cli/internal/tui/discord_render.go | 5 ++- cli/internal/tui/folder_picker_test.go | 10 ++++- cli/internal/tui/folder_picker_view.go | 51 ++++++++++++++++---------- cli/internal/tui/session_choice.go | 14 +++++-- cli/internal/tui/webhooks_page_test.go | 3 ++ cli/internal/tui/webhooks_render.go | 16 +++++--- 6 files changed, 69 insertions(+), 30 deletions(-) diff --git a/cli/internal/tui/discord_render.go b/cli/internal/tui/discord_render.go index c368e522..c8af3e48 100644 --- a/cli/internal/tui/discord_render.go +++ b/cli/internal/tui/discord_render.go @@ -9,6 +9,7 @@ import ( "time" "charm.land/lipgloss/v2" + "github.com/charmbracelet/x/ansi" ) // View draws the bot list beside the highlighted bot, or the open bot's @@ -292,7 +293,7 @@ func (m DiscordPageModel) botDetails(bot daemon.DiscordBot, width int) []string dms += " · " + plural(bot.Requests, "request") + " waiting" } lines = append(lines, factRows("dms", dms, width)...) - lines = append(lines, factRows("invite", cmp.Or(bot.Invite, "appears once the bot has connected"), width)...) + lines = append(lines, factRows("invite", ansi.Truncate(cmp.Or(bot.Invite, "once the bot connects"), max(1, width-10), "…"), width)...) lines = append(lines, "") return append(lines, paneNote("Enter chooses its channels and who may DM it.", width)...) } @@ -432,7 +433,7 @@ func (m DiscordPageModel) personDetails(kind, user string, width int) []string { lines = append(lines, factRows("user id", r.UserID, width)...) lines = append(lines, factRows("sent", plural(r.Count, "message")+" · last "+ago(now, r.LastAt), width)...) lines = append(lines, "", DefaultStyles.Muted.Render("latest")) - for _, l := range svWrap(r.Preview, width, 6) { + for _, l := range svWrap(r.Preview, max(1, width-2), 6) { lines = append(lines, " "+l) } return append(append(lines, ""), paneNote("Refused DMs never reach the session. enter allows them from now on; ctrl+x dismisses.", width)...) diff --git a/cli/internal/tui/folder_picker_test.go b/cli/internal/tui/folder_picker_test.go index 7d27db95..998e4582 100644 --- a/cli/internal/tui/folder_picker_test.go +++ b/cli/internal/tui/folder_picker_test.go @@ -244,7 +244,7 @@ func TestPickerBrowsesAHostFoldingUnderItsHome(t *testing.T) { // back among the recent folders, the remote one reads like the preview's rule m.setQuery("") m.cursor = slices.IndexFunc(m.rows, func(r folderRow) bool { return r.hostKey != "" }) - if row := m.row(m.rows[m.cursor], false, false, false, 60, time.Now()); !strings.Contains(ansi.Strip(row), "chernobog:proj") { + if row := m.row(m.rows[m.cursor], false, false, false, 60, 12, time.Now()); !strings.Contains(ansi.Strip(row), "chernobog:proj") { t.Fatalf("a recent remote folder's where should read host:path under its home: %q", ansi.Strip(row)) } if len(src.warmed) != 1 { @@ -358,6 +358,14 @@ func TestFolderFooterKeepsRetryWhenSessionsFail(t *testing.T) { } } +func TestFolderFooterKeepsAMissingFolderWhole(t *testing.T) { + m := NewFolderPicker(remoteFolders("ready", ""), daemon.Session{ID: "a", Workspace: "/srv/here"}, &WorkspaceRetry{Missing: "/srv/proj/gone"}) + m.SetSize(100, 24) + if footer := ansi.Strip(m.footer(100)); !strings.Contains(footer, "Folder not found: /srv/proj/gone") { + t.Fatalf("the footer cut the missing folder: %q", footer) + } +} + func TestFolderPickerCtrlDGoesBack(t *testing.T) { m := NewFolderBrowser(remoteFolders("ready", ""), "/Users/dawn/proj/albedo", "") m.SetSize(100, 16) diff --git a/cli/internal/tui/folder_picker_view.go b/cli/internal/tui/folder_picker_view.go index e88a90fa..754b094d 100644 --- a/cli/internal/tui/folder_picker_view.go +++ b/cli/internal/tui/folder_picker_view.go @@ -53,15 +53,12 @@ func (m FolderPicker) View() string { } // narrowKeys is the width the full keys need beside a status; less than that -// and a failed session list keeps only its retry. minStatusRoom is the least -// a status can have beside the keys. -const ( - narrowKeys = 28 - minStatusRoom = 16 -) +// and a failed session list keeps only its retry. +const narrowKeys = 28 // footer is the keys on the left and the most pressing thing to say on the -// right, which takes what the keys leave. +// right: an urgent one whole, for footerLine to place, a quiet one in what +// the keys leave. func (m FolderPicker) footer(width int) string { hints := m.hints() keys := " " + keyHints(hints...) @@ -69,11 +66,10 @@ func (m FolderPicker) footer(width int) string { hints = []hint{m.retryHint()} keys = " " + keyHints(hints...) } - room := width - ansi.StringWidth(keys) - 3 - if room < minStatusRoom { - room = width - 2 // too little beside the keys: an urgent status takes a row of its own + status, urgent := m.status(width - 2) + if !urgent { + status, _ = m.status(width - ansi.StringWidth(keys) - 3) } - status, urgent := m.status(room) return footerLine(width, hints, status, urgent) } @@ -152,13 +148,17 @@ func (m FolderPicker) list(width, height int) []string { return scrollWindow([]string{sectionRule(m.section, 0, width), DefaultStyles.Faint.Render(" " + m.emptyNote())}, 1, width, height) } here, latest := m.workspace(), m.latestOther() + tagW := 0 + if slices.ContainsFunc(m.rows, func(r folderRow) bool { return repoTag(m.repos[r.path]) != "" }) { + tagW = 12 + } now := time.Now() return drawWindow(len(m.rows)+1, func(i int) string { if i == 0 { return sectionRule(m.section, len(m.rows), width) } row := m.rows[i-1] - return m.row(row, i-1 == m.cursor, row.path == here, row.path == latest, width, now) + return m.row(row, i-1 == m.cursor, row.path == here, row.path == latest, width, tagW, now) }, m.cursor+1, width, height) } @@ -238,8 +238,10 @@ func (m FolderPicker) reach(row folderRow) (note string, style lipgloss.Style, d } // row is a folder in the sessions view's grammar: bar, glyph, name with -// the matched letters lit, then quiet columns for where, head and age. -func (m FolderPicker) row(row folderRow, selected, here, latest bool, width int, now time.Time) string { +// the matched letters lit, then quiet columns for where, head and age. The +// head column is tagW wide, none when no row has a head, and where takes +// what the others leave. +func (m FolderPicker) row(row folderRow, selected, here, latest bool, width, tagW int, now time.Time) string { glyph, glyphStyle := "· ", DefaultStyles.Faint switch { case selected: @@ -249,11 +251,15 @@ func (m FolderPicker) row(row folderRow, selected, here, latest bool, width int, case latest: glyph, glyphStyle = "● ", DefaultStyles.Success } - whereW, tagW, ageW := 0, 12, 4 + ageW, tail := 4, 6 + if tagW > 0 { + tail += tagW + 2 + } + nameW, whereW, noteW := min(18, max(4, width-4-tail)), 0, max(tail-2, 18) if (row.recent || row.hostRow) && width >= 48 { - whereW = 16 + nameW = min(18, max(4, width-4-tail-14)) + whereW = width - 4 - nameW - 2 - tail } - nameW := min(18, max(4, width-4-(whereW+2)-(tagW+2)-(ageW+2))) bar := " " if selected { bar = selectBar() @@ -267,17 +273,24 @@ func (m FolderPicker) row(row folderRow, selected, here, latest bool, width int, base = DefaultStyles.Bold } line := bar + glyphStyle.Render(glyph) + " " + litName(row.name, row.matched, nameW, base) + if note != "" { + if whereW -= noteW - (tail - 2); whereW < 8 { + whereW, noteW = 0, width-6-nameW + } + } if whereW > 0 { line += " " + DefaultStyles.Faint.Render(svCell(m.where(row), whereW, false)) } if note != "" { - line += " " + noteStyle.Render(svCell(note, tagW+2+ageW, false)) + line += " " + noteStyle.Render(svCell(note, noteW, false)) if selected { return selectedLine(line, width) } return line } - line += " " + DefaultStyles.Faint.Render(svCell(repoTag(m.repos[row.path]), tagW, false)) + if tagW > 0 { + line += " " + DefaultStyles.Faint.Render(svCell(repoTag(m.repos[row.path]), tagW, false)) + } age := "" if here { age = "here" diff --git a/cli/internal/tui/session_choice.go b/cli/internal/tui/session_choice.go index 8d5fcfc7..8a95b76b 100644 --- a/cli/internal/tui/session_choice.go +++ b/cli/internal/tui/session_choice.go @@ -72,9 +72,10 @@ func (c sessionChoice) rows(query, indent string, width int) []string { } chosen := max(0, c.chosenIndex(matches)) start := max(0, min(chosen-sessionChoices/2, len(matches)-sessionChoices)) + end := min(len(matches), start+sessionChoices) var rows []string w := width - len(indent) - for i := start; i < min(len(matches), start+sessionChoices); i++ { + for i := start; i < end; i++ { label := sessionLabel(c.Sessions, matches[i].ID, c.Current) if i == chosen { rows = append(rows, indent+selectedLine(ansi.Truncate(selectBar()+" "+label, w, "…"), w)) @@ -82,8 +83,15 @@ func (c sessionChoice) rows(query, indent string, width int) []string { rows = append(rows, indent+DefaultStyles.Faint.Render(ansi.Truncate(" "+label, w, "…"))) } } - if more := len(matches) - sessionChoices; more > 0 { - rows = append(rows, indent+DefaultStyles.Faint.Render(fmt.Sprintf(" %d more · type to filter", more))) + var hidden []string + if start > 0 { + hidden = append(hidden, fmt.Sprintf("%d above", start)) + } + if end < len(matches) { + hidden = append(hidden, fmt.Sprintf("%d below", len(matches)-end)) + } + if len(hidden) > 0 { + rows = append(rows, indent+DefaultStyles.Faint.Render(" "+strings.Join(append(hidden, "type to filter"), " · "))) } return rows } diff --git a/cli/internal/tui/webhooks_page_test.go b/cli/internal/tui/webhooks_page_test.go index 4361419d..32f0beff 100644 --- a/cli/internal/tui/webhooks_page_test.go +++ b/cli/internal/tui/webhooks_page_test.go @@ -221,6 +221,9 @@ func TestWebhookListAndCopyUseTheIntakeAddress(t *testing.T) { if plain := ansi.Strip(m.View()); !strings.Contains(plain, address) { t.Fatalf("list did not show the intake address:\n%s", plain) } + if footer := ansi.Strip(m.footer(120)); !strings.Contains(footer, "ctrl+l copy url") { + t.Fatalf("the footer dropped ctrl+l before the session's chords: %q", footer) + } m.SetSize(70, 20) if plain := ansi.Strip(m.View()); !strings.Contains(plain, "url POST http://127.0.0.1") { t.Fatalf("a narrow pane lost the url:\n%s", plain) diff --git a/cli/internal/tui/webhooks_render.go b/cli/internal/tui/webhooks_render.go index 023bc136..ee3258d5 100644 --- a/cli/internal/tui/webhooks_render.go +++ b/cli/internal/tui/webhooks_render.go @@ -4,6 +4,7 @@ import ( "cmp" "fmt" "slices" + "strings" "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" @@ -12,7 +13,7 @@ import ( // View draws the list beside the highlighted hook's detail. The form and the // secret shown once take the list's place, and a question takes the footer. func (m WebhooksPageModel) View() string { - frame := m.listView.frame(brand("albedo")+" "+DefaultStyles.Muted.Render("/webhooks"), DefaultStyles.Faint.Render("all sessions"), m.footer(max(1, m.Width))) + frame := m.listView.frame(brand("albedo")+" "+DefaultStyles.Muted.Render("/webhooks"), DefaultStyles.Faint.Render("all sessions · agent access "+onOff(m.AgentManagement)), m.footer(max(1, m.Width))) switch { case m.Reveal != nil: frame.filter, frame.pane, frame.list = "", nil, m.revealRows @@ -87,7 +88,8 @@ func (m WebhooksPageModel) status() (string, bool) { return "", false } -// browseHints keeps the main hook action and session agent access visible first. +// browseHints keeps the main hook action and session agent access visible +// first, then the hook's own actions. func (m WebhooksPageModel) browseHints() []hint { if !m.Loaded { return []hint{{"ctrl+r", "retry"}, {"esc", "back"}} @@ -97,9 +99,9 @@ func (m WebhooksPageModel) browseHints() []hint { if selected { hints = append(hints, hint{"enter", "on/off"}) } - hints = append(hints, hint{"ctrl+t", "agent access " + onOff(m.AgentManagement)}, hint{"ctrl+o", "add hook"}) + hints = append(hints, hint{"ctrl+t", "agent access"}, hint{"ctrl+o", "add hook"}) if selected { - hints = append(hints, hint{"ctrl+e", "edit"}, hint{"ctrl+d", "delete"}, hint{"ctrl+g", "new secret"}, hint{"ctrl+l", "copy url"}) + hints = append(hints, hint{"ctrl+e", "edit"}, hint{"ctrl+l", "copy url"}, hint{"ctrl+d", "delete"}, hint{"ctrl+g", "new secret"}) } return append(hints, hint{"ctrl+r", "refresh"}, hint{"esc", "back"}) } @@ -109,7 +111,11 @@ func (m WebhooksPageModel) formFooter(width int) string { line := m.Form.footer(width) switch { case m.Error != "": - return footerLine(width, nil, DefaultStyles.Error.Render(m.Error), true) + "\n" + line + var rows []string + for _, l := range svWrap(m.Error, max(1, width-2), 2) { + rows = append(rows, " "+DefaultStyles.Error.Render(l)) + } + return strings.Join(append(rows, line), "\n") case m.Saving: return footerLine(width, nil, DefaultStyles.Busy.Render("saving…"), true) + "\n" + line } -- knotmirror 0.0.1