display

package
v0.14.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package display provides shared text formatting utilities for CLI and server. This package consolidates display logic to ensure consistency across all interfaces.

Index

Constants

View Source
const (
	ColorCyan    = "#00bcd4"
	ColorGreen   = "#4caf50"
	ColorYellow  = "#ff9800"
	ColorRed     = "#f44336"
	ColorMagenta = "#9c27b0"
	ColorGray    = "#9e9e9e"
	ColorBlue    = "#2196f3"
)

Color constants for consistent theming across CLI and frontend.

Variables

This section is empty.

Functions

func CompactJSON

func CompactJSON(data string) string

CompactJSON removes whitespace from a JSON string. Returns the original string if it's not valid JSON.

func FormatAge

func FormatAge(t time.Time) string

FormatAge formats a time as a human-readable relative age string. Examples: "just now", "5m ago", "2h ago", "3d ago", "Jan 15"

func FormatDuration

func FormatDuration(ms float64) string

FormatDuration formats a duration in milliseconds for display. Returns "-" for zero, "123ms" for <1s, "1.5s" for >=1s.

func FormatDurationFromDuration

func FormatDurationFromDuration(d time.Duration) string

FormatDurationFromDuration formats a time.Duration for display.

func FormatJSONKeyValue

func FormatJSONKeyValue(data string, maxValueLen int) string

FormatJSONKeyValue formats a JSON object's key-value pairs for display. Each key-value pair is formatted on its own line with truncation.

func FormatJSONValue

func FormatJSONValue(val interface{}, maxLen int) string

FormatJSONValue formats a JSON value as a string for display. Truncates long values and handles nested objects.

func FormatRelativeTime

func FormatRelativeTime(t time.Time) string

FormatRelativeTime formats a time relative to now, with direction. Examples: "in 5m", "5m ago"

func FormatTimeRange

func FormatTimeRange(start, end time.Time) string

FormatTimeRange formats a time range (start to end) concisely.

func FormatTimestamp

func FormatTimestamp(t time.Time) string

FormatTimestamp formats a timestamp for log-style display. Examples: "15:04:05" for today, "Jan 2 15:04" for this year, "2024-01-15 15:04" otherwise.

func FormatTimestampShort

func FormatTimestampShort(t time.Time) string

FormatTimestampShort returns a compact timestamp for tables.

func IsJSON

func IsJSON(s string) bool

IsJSON checks if a string is valid JSON.

func PrettyJSON

func PrettyJSON(data string) string

PrettyJSON formats a JSON string with indentation. Returns the original string if it's not valid JSON.

func SanitizeNewlines

func SanitizeNewlines(s string) string

SanitizeNewlines replaces newlines with spaces for single-line display.

func Truncate

func Truncate(s string, maxLen int) string

Truncate truncates a string to maxLen characters, adding "..." if truncated. If maxLen is 0 or negative, returns the original string.

func TruncateFirstLine

func TruncateFirstLine(text string, maxLen int) string

TruncateFirstLine returns the first line of text, truncated to maxLen. Useful for prompts and multi-line strings.

func TruncateID

func TruncateID(id string, length ...int) string

TruncateID truncates an ID string (like UUIDs) to a short form. Default length is 12 characters if not specified.

func TruncateMiddle

func TruncateMiddle(s string, maxLen int) string

TruncateMiddle truncates a string by removing the middle portion. Useful for file paths: "/Users/mark/.../file.go"

func TruncateOutput

func TruncateOutput(output string, maxLen int) string

TruncateOutput truncates output text and trims whitespace. Convenience function for tool outputs and results.

func WordWrapIndent

func WordWrapIndent(text string, width int, indent string) string

WordWrapIndent wraps text at width and adds a prefix indent to each line.

func WrapText

func WrapText(text string, width int) string

WrapText wraps text at the specified width, preserving existing newlines. If a single word is longer than width, it won't be broken.

Types

type StatusDisplay

type StatusDisplay struct {
	// Label is the human-readable status text (e.g., "Running", "Completed")
	Label string `json:"label"`
	// Color is a hex color code (e.g., "#00bcd4" for cyan)
	Color string `json:"color"`
	// Icon is a unicode icon character (e.g., "▶", "✓", "✗")
	Icon string `json:"icon"`
	// Severity indicates the status category for styling
	Severity StatusSeverity `json:"severity"`
}

StatusDisplay contains display information for a status value. This struct can be embedded in API responses for consistent rendering.

func ApprovalStatusDisplay

func ApprovalStatusDisplay(status string) StatusDisplay

ApprovalStatusDisplay returns display information for approval statuses.

func EventTypeDisplay

func EventTypeDisplay(eventType string) StatusDisplay

EventTypeDisplay returns display information for event stream types.

func MessageStatusDisplay

func MessageStatusDisplay(status string) StatusDisplay

MessageStatusDisplay returns display information for inbox message statuses.

func TaskStatusDisplay

func TaskStatusDisplay(status string) StatusDisplay

TaskStatusDisplay returns display information for coordinator task statuses. The status parameter should be the task status string (e.g., "pending", "running").

type StatusSeverity

type StatusSeverity string

StatusSeverity indicates the general category of a status.

const (
	SeverityInfo    StatusSeverity = "info"
	SeveritySuccess StatusSeverity = "success"
	SeverityWarning StatusSeverity = "warning"
	SeverityError   StatusSeverity = "error"
	SeverityMuted   StatusSeverity = "muted"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL