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: 21 additions & 3 deletions internal/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2215,9 +2215,7 @@ func TestMarkdownRenderObjectPreservesURLs(t *testing.T) {
}

func TestStyledRenderTablePreservesURLs(t *testing.T) {
// URL must be >40 chars (to exercise the cap exemption) but short enough
// to fit beside "name" in an 80-char default terminal.
url := "https://3.basecampapi.com/1234567/todolists/98765.json"
url := "https://3.basecampapi.com/1234567/buckets/12345678/todolists/9876543210.json"
data := []any{
map[string]any{"name": "Tasks", "todolists_url": url},
}
Expand Down Expand Up @@ -2518,12 +2516,32 @@ func TestSelectColumnsExemptsURLColumnsForSuffixFields(t *testing.T) {
}
selected := r.selectColumns(cols, data)

var found bool
for _, col := range selected {
if col.key == "todolists_url" {
found = true
assert.Greater(t, col.width, 40, "URL column with _url suffix should retain actual width")
assert.True(t, col.containsURL, "URL column should be flagged")
}
}
Comment thread
jeremy marked this conversation as resolved.
require.True(t, found, "todolists_url column must be present in selected columns")
}

func TestSelectColumnsPreservesURLColumnsWhenOverflowing(t *testing.T) {
url := "https://3.basecampapi.com/1234567/buckets/12345678/people/9999999.json"
r := &Renderer{width: 60} // URL (70) + name (5) + padding (4) = 79 > 60
cols := []column{
{key: "name", header: "Name", priority: 2},
{key: "href", header: "Href", priority: 5},
}
data := []map[string]any{
{"name": "Alice", "href": url},
}
selected := r.selectColumns(cols, data)

require.Len(t, selected, 2, "both columns should survive even when total exceeds terminal width")
assert.Equal(t, "href", selected[1].key)
assert.Equal(t, len(url), selected[1].width, "URL column should retain its full measured width")
}

// =============================================================================
Expand Down
14 changes: 13 additions & 1 deletion internal/output/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,19 @@ func (r *Renderer) selectColumns(cols []column, data []map[string]any) []column
if total <= r.width {
break
}
selected = selected[:len(selected)-1]
// Drop the rightmost non-URL column. A dropped URL is useless;
// an overflowing table at least keeps the link clickable.
dropped := false
for j := len(selected) - 1; j >= 1; j-- {
if !selected[j].containsURL {
selected = append(selected[:j], selected[j+1:]...)
dropped = true
break
}
}
if !dropped {
break // only the lead column and URL columns remain
}
}

return selected
Expand Down
Loading