Library: cut long titles to the width of the list
Long titles made the movies and series tables wider than their pane, so they scrolled sideways and status and size left the view. The title column is now cut on every draw to what the other columns leave, ending in an ellipsis (done by hand: tview only draws its ellipsis for untagged text, and every title starts with the colored monitored mark). Titles are now escaped, so square brackets in them are not taken as color tags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019reK4DUGYqDUjniWYJvwUW
This commit is contained in:
@@ -5,6 +5,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/arr"
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/radarr"
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/sonarr"
|
||||
@@ -257,3 +260,51 @@ func TestRemovingATitleKeepsThePlace(t *testing.T) {
|
||||
t.Errorf("filtered out: row %d, want the top", r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongTitlesAreCutToTheList(t *testing.T) {
|
||||
sim := tcell.NewSimulationScreen("")
|
||||
if err := sim.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer sim.Fini()
|
||||
sim.SetSize(40, 5)
|
||||
|
||||
tbl := tview.NewTable().SetSelectable(true, false).SetFixed(1, 0)
|
||||
header(tbl, 0, "Title", "Status", "Size")
|
||||
title := titleCell{prefix: monMark(true) + " ", title: "Neon Genesis Evangelion: The End of Evangelion (1997)"}
|
||||
tbl.SetCell(1, 0, tview.NewTableCell(title.fit(0)).SetExpansion(1).SetReference(title))
|
||||
tbl.SetCell(1, 1, tview.NewTableCell("missing"))
|
||||
tbl.SetCell(1, 2, tview.NewTableCell("12.3 GB").SetAlign(tview.AlignRight))
|
||||
tbl.SetRect(0, 0, 40, 5)
|
||||
fitTitles{tbl}.Draw(sim)
|
||||
|
||||
row := rowText(sim, 1, 0, 40)
|
||||
if !strings.HasSuffix(strings.TrimRight(row, " "), "12.3 GB") || !strings.Contains(row, "missing") {
|
||||
t.Errorf("status and size must stay in view: %q", row)
|
||||
}
|
||||
if !strings.Contains(row, "…") {
|
||||
t.Errorf("the cut title should end in an ellipsis: %q", row)
|
||||
}
|
||||
if !strings.HasPrefix(row, "● Neon Genesis") {
|
||||
t.Errorf("the title should start at the left edge: %q", row)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCutToWidth(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
in string
|
||||
w int
|
||||
want string
|
||||
}{
|
||||
{"Dune (2021)", 20, "Dune (2021)"},
|
||||
{"Dune (2021)", 11, "Dune (2021)"},
|
||||
{"Dune (2021)", 8, "Dune (2…"},
|
||||
{"千と千尋の神隠し", 7, "千と千…"}, // wide characters count twice
|
||||
{"[Rec] (2007)", 6, "[Rec]…"}, // brackets are text, not color tags
|
||||
{"Dune", 0, ""},
|
||||
} {
|
||||
if got := cutToWidth(tc.in, tc.w); got != tc.want {
|
||||
t.Errorf("cutToWidth(%q, %d) = %q, want %q", tc.in, tc.w, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user