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
70 changes: 70 additions & 0 deletions internal/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,76 @@ func TestRenderObjectOrdering(t *testing.T) {
assert.Less(t, createdPos, updatedPos, "Created (priority 8) should appear before Updated (priority 9)")
}

// =============================================================================
// renderObject Detail Value (no truncation) Tests
// =============================================================================

func TestRenderObjectDetailValueNotTruncated(t *testing.T) {
longContent := "This is a very long description that clearly exceeds the forty character truncation limit used by table cells"

t.Run("styled output preserves full content", func(t *testing.T) {
var buf bytes.Buffer
w := New(Options{
Format: FormatStyled,
Writer: &buf,
})

data := map[string]any{
"id": float64(1),
"description": longContent,
}

err := w.OK(data)
require.NoError(t, err)

output := buf.String()
assert.Contains(t, output, longContent,
"detail view should show full content without truncation")
assert.NotContains(t, output, "...",
"detail view should not contain truncation ellipsis")
})

t.Run("markdown output preserves full content", func(t *testing.T) {
var buf bytes.Buffer
w := New(Options{
Format: FormatMarkdown,
Writer: &buf,
})

data := map[string]any{
"id": float64(1),
"description": longContent,
}

err := w.OK(data)
require.NoError(t, err)

output := buf.String()
assert.Contains(t, output, longContent,
"markdown detail view should show full content without truncation")
})

t.Run("HTML content is converted to markdown", func(t *testing.T) {
var buf bytes.Buffer
w := New(Options{
Format: FormatStyled,
Writer: &buf,
})

data := map[string]any{
"id": float64(1),
"content": "<p>Status report with important details about the project</p>",
}

err := w.OK(data)
require.NoError(t, err)

output := buf.String()
assert.Contains(t, output, "Status report with important details about the project")
assert.NotContains(t, output, "<p>")
})
}

// =============================================================================
// renderObject Header Humanization Tests
// =============================================================================
Expand Down
38 changes: 32 additions & 6 deletions internal/output/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (r *Renderer) renderObject(b *strings.Builder, data map[string]any) {
label := formatHeader(f.key)
labelStyled := r.Muted.Render(fmt.Sprintf("%-*s: ", maxLen, label))

value := formatDateValue(f.key, data[f.key])
value := formatDetailValue(f.key, data[f.key])
// Hyperlink title/name fields when styled
if r.styled && (f.key == "title" || f.key == "name") {
if url, ok := data["app_url"].(string); ok && url != "" {
Expand Down Expand Up @@ -792,14 +792,40 @@ func formatTableCell(key string, val any) string {
return formatDateValue(key, val)
}

// formatDetailValue formats a value for detail (single-object) display.
// Date columns get human-readable formatting via formatDateValue.
// Unlike formatCell, string values are not truncated — detail views show full content.
func formatDetailValue(key string, val any) string {
if isDateColumn(key) {
return formatDateValue(key, val)
}

switch v := val.(type) {
case nil:
return ""
case string:
v = ansi.Strip(v)
if richtext.IsHTML(v) {
v = richtext.HTMLToMarkdown(v)
}
if strings.ContainsAny(v, "\n\r") {
v = strings.Join(strings.Fields(v), " ")
}
return v
default:
return formatCell(val)
}
}

// formatDateValue formats date fields in a human-readable way.
// For date columns (created_at, updated_at, due_on, due_date), it converts
// ISO8601 timestamps to a more readable format.
func formatDateValue(key string, val any) string {
// Check if this is a date column
isDateColumn := strings.HasSuffix(key, "_at") || strings.HasSuffix(key, "_on") || strings.HasSuffix(key, "_date")
func isDateColumn(key string) bool {
return strings.HasSuffix(key, "_at") || strings.HasSuffix(key, "_on") || strings.HasSuffix(key, "_date")
}

if !isDateColumn {
func formatDateValue(key string, val any) string {
if !isDateColumn(key) {
return formatCell(val)
}

Expand Down Expand Up @@ -1071,7 +1097,7 @@ func (r *MarkdownRenderer) renderObject(b *strings.Builder, data map[string]any)

for _, f := range fields {
label := formatHeader(f.key)
value := formatDateValue(f.key, data[f.key])
value := formatDetailValue(f.key, data[f.key])
b.WriteString("- **" + label + ":** " + value + "\n")
}
}
Expand Down
Loading