From 113b99dc3046b9356d2dceb0f13ed032329e6619 Mon Sep 17 00:00:00 2001 From: "Calmcacil B." <716671+calmcacil@users.noreply.github.com> Date: Thu, 16 Jul 2026 23:32:05 +0200 Subject: [PATCH] fix(anime): repair search result layout --- internal/anisearch/anisearch_test.go | 29 ++++++++++++++++++++++++++++ internal/anisearch/render.go | 6 +++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/internal/anisearch/anisearch_test.go b/internal/anisearch/anisearch_test.go index c20fa47..8484c7d 100644 --- a/internal/anisearch/anisearch_test.go +++ b/internal/anisearch/anisearch_test.go @@ -15,6 +15,7 @@ import ( "testing" "time" + "github.com/calmcacil/CalmsToolkit/internal/colors" "github.com/calmcacil/CalmsToolkit/internal/config" "github.com/calmcacil/CalmsToolkit/internal/core" "github.com/klauspost/compress/zstd" @@ -702,6 +703,34 @@ func TestTruncateVis(t *testing.T) { } } +func TestRenderSearchResultsLayout(t *testing.T) { + title := "Frieren: Beyond Journey’s End" + episodes := 28 + score := 91 + result := &SearchResult{ + Media: []Show{{ + Title: Title{English: &title}, + Format: "TV", + Episodes: &episodes, + AverageRank: &score, + Status: "FINISHED", + }}, + PageInfo: PageInfo{CurrentPage: 1, HasNextPage: true}, + } + + output := renderSearchResults("Frieren", result, -1, nil, ToolConfig{CommonConfig: core.CommonConfig{NoColor: true}}) + if !strings.Contains(output, "[TV] 28 eps · 91% [Finished]") { + t.Fatalf("search result metadata is not spaced correctly:\n%s", output) + } + + const wantWidth = 80 + for i, line := range strings.Split(strings.TrimSuffix(output, "\n"), "\n") { + if got := colors.VisibleLen(line); got != wantWidth { + t.Errorf("line %d width = %d, want %d: %q", i+1, got, wantWidth, line) + } + } +} + func TestFormatEpisodes(t *testing.T) { tests := []struct { name string diff --git a/internal/anisearch/render.go b/internal/anisearch/render.go index 0edc5a2..e4e85d6 100644 --- a/internal/anisearch/render.go +++ b/internal/anisearch/render.go @@ -27,8 +27,8 @@ func innerWidth() int { if w < 40 { w = 40 } - if w > 100 { - w = 100 + if w > 80 { + w = 80 } return w - 2 // subtract box borders } @@ -123,7 +123,7 @@ func formatSearchLine(num int, show Show, highlighted bool, mapping *AnibridgeMa scoreLabel = fmt.Sprintf(" · %s%d%%%s", clr(p.Accent), *show.AverageRank, clr(p.Reset)) } - meta := fmt.Sprintf(" %s% s%s%s", clr(p.Subdued), fmtBadge, epLabel, scoreLabel) + meta := fmt.Sprintf(" %s%s %s%s", clr(p.Subdued), fmtBadge, epLabel, scoreLabel) // Status indicator statusLabel := ""