Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions internal/anisearch/anisearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,30 @@ func TestWriteTerminalFramePreservesNewlinesOutsideRawMode(t *testing.T) {
}
}

func TestRenderDetailContainsLongFields(t *testing.T) {
long := strings.Repeat("very-long-value-", 20)
show := Show{
Title: Title{English: &long, Native: &long},
Format: long,
Status: long,
Season: long,
Genres: []string{long},
Tags: []Tag{{Name: long}},
Description: long,
Studios: &Studios{Nodes: []StudioNode{{Name: long}}},
}

const wantWidth = 80
for _, noColor := range []bool{true, false} {
output := renderDetail(show, 424536, ToolConfig{CommonConfig: core.CommonConfig{NoColor: noColor}})
for i, line := range strings.Split(strings.TrimSuffix(output, "\n"), "\n") {
if got := colors.VisibleLen(line); got != wantWidth {
t.Errorf("NoColor=%t line %d width = %d, want %d: %q", noColor, i+1, got, wantWidth, line)
}
}
}
}

func TestFormatEpisodes(t *testing.T) {
tests := []struct {
name string
Expand Down
34 changes: 16 additions & 18 deletions internal/anisearch/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ func renderDetail(show Show, tvdbID int, cfg ToolConfig) string {

// Top border + title
title := " " + show.Title.DisplayTitle() + " "
title = truncateVis(title, iW)
topLine := "┌" + title + strings.Repeat("─", iW-colors.VisibleLen(title)) + "┐\n"
bw.WriteString(topLine)

// Native title (if different from display title)
if show.Title.Native != nil && *show.Title.Native != "" &&
(show.Title.Romaji == nil || *show.Title.Romaji != *show.Title.Native) &&
(show.Title.English == nil || *show.Title.English != *show.Title.Native) {
nativeLine := " " + clr(p.Subdued) + *show.Title.Native + clr(p.Reset)
nativeTitle := truncateVis(*show.Title.Native, iW-1)
nativeLine := " " + clr(p.Subdued) + nativeTitle + clr(p.Reset)
nativeLine = colors.PadRight(nativeLine, iW)
bw.WriteString("│" + nativeLine + "│\n")
}
Expand All @@ -203,28 +205,22 @@ func renderDetail(show Show, tvdbID int, cfg ToolConfig) string {
left := infoRows[row*2]
right := infoRows[row*2+1]

leftStr := fmt.Sprintf(" %s%s:%s %s", clr(p.Bold), left[0], clr(p.Reset), left[1])
rightStr := fmt.Sprintf("%s%s:%s %s", clr(p.Bold), right[0], clr(p.Reset), right[1])

// Layout: leftStr | padding | rightStr, totaling iW
leftVis := colors.VisibleLen(leftStr)
colWidth := iW / 2
if leftVis > colWidth {
leftStr = truncateVis(leftStr, colWidth)
leftVis = colors.VisibleLen(leftStr)
}
padding := iW - leftVis - colors.VisibleLen(rightStr) - 1 // -1 for space
if padding < 1 {
padding = 1
}
line := leftStr + strings.Repeat(" ", padding) + rightStr
line = colors.PadRight(line, iW)
rightWidth := iW - colWidth
leftPrefix := fmt.Sprintf(" %s%s:%s ", clr(p.Bold), left[0], clr(p.Reset))
rightPrefix := fmt.Sprintf("%s%s:%s ", clr(p.Bold), right[0], clr(p.Reset))
leftValue := truncateVis(left[1], colWidth-colors.VisibleLen(leftPrefix))
rightValue := truncateVis(right[1], rightWidth-colors.VisibleLen(rightPrefix))
leftStr := colors.PadRight(leftPrefix+leftValue, colWidth)
rightStr := colors.PadRight(rightPrefix+rightValue, rightWidth)
line := leftStr + rightStr
bw.WriteString("│" + line + "│\n")
}

// Genres
if len(show.Genres) > 0 {
genreLine := " " + clr(p.Subdued) + strings.Join(show.Genres, ", ") + clr(p.Reset)
genres := truncateVis(strings.Join(show.Genres, ", "), iW-1)
genreLine := " " + clr(p.Subdued) + genres + clr(p.Reset)
genreLine = colors.PadRight(genreLine, iW)
bw.WriteString("│" + genreLine + "│\n")
}
Expand All @@ -239,7 +235,8 @@ func renderDetail(show Show, tvdbID int, cfg ToolConfig) string {
}
}
if len(tagNames) > 0 {
tagLine := " " + clr(p.Subdued) + "Tags: " + strings.Join(tagNames, ", ") + clr(p.Reset)
tags := truncateVis("Tags: "+strings.Join(tagNames, ", "), iW-1)
tagLine := " " + clr(p.Subdued) + tags + clr(p.Reset)
tagLine = colors.PadRight(tagLine, iW)
bw.WriteString("│" + tagLine + "│\n")
}
Expand All @@ -261,6 +258,7 @@ func renderDetail(show Show, tvdbID int, cfg ToolConfig) string {
lines = append(lines, clr(p.Subdued)+"... (truncated)"+clr(p.Reset))
}
for _, line := range lines {
line = truncateVis(line, iW-2)
line = " " + line
line = colors.PadRight(line, iW)
bw.WriteString("│" + line + "│\n")
Expand Down