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
- func CompactJSON(data string) string
- func FormatAge(t time.Time) string
- func FormatDuration(ms float64) string
- func FormatDurationFromDuration(d time.Duration) string
- func FormatJSONKeyValue(data string, maxValueLen int) string
- func FormatJSONValue(val interface{}, maxLen int) string
- func FormatRelativeTime(t time.Time) string
- func FormatTimeRange(start, end time.Time) string
- func FormatTimestamp(t time.Time) string
- func FormatTimestampShort(t time.Time) string
- func IsJSON(s string) bool
- func PrettyJSON(data string) string
- func SanitizeNewlines(s string) string
- func Truncate(s string, maxLen int) string
- func TruncateFirstLine(text string, maxLen int) string
- func TruncateID(id string, length ...int) string
- func TruncateMiddle(s string, maxLen int) string
- func TruncateOutput(output string, maxLen int) string
- func WordWrapIndent(text string, width int, indent string) string
- func WrapText(text string, width int) string
- type StatusDisplay
- type StatusSeverity
Constants ¶
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 ¶
CompactJSON removes whitespace from a JSON string. Returns the original string if it's not valid JSON.
func FormatAge ¶
FormatAge formats a time as a human-readable relative age string. Examples: "just now", "5m ago", "2h ago", "3d ago", "Jan 15"
func FormatDuration ¶
FormatDuration formats a duration in milliseconds for display. Returns "-" for zero, "123ms" for <1s, "1.5s" for >=1s.
func FormatDurationFromDuration ¶
FormatDurationFromDuration formats a time.Duration for display.
func FormatJSONKeyValue ¶
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 ¶
FormatJSONValue formats a JSON value as a string for display. Truncates long values and handles nested objects.
func FormatRelativeTime ¶
FormatRelativeTime formats a time relative to now, with direction. Examples: "in 5m", "5m ago"
func FormatTimeRange ¶
FormatTimeRange formats a time range (start to end) concisely.
func FormatTimestamp ¶
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 ¶
FormatTimestampShort returns a compact timestamp for tables.
func PrettyJSON ¶
PrettyJSON formats a JSON string with indentation. Returns the original string if it's not valid JSON.
func SanitizeNewlines ¶
SanitizeNewlines replaces newlines with spaces for single-line display.
func Truncate ¶
Truncate truncates a string to maxLen characters, adding "..." if truncated. If maxLen is 0 or negative, returns the original string.
func TruncateFirstLine ¶
TruncateFirstLine returns the first line of text, truncated to maxLen. Useful for prompts and multi-line strings.
func TruncateID ¶
TruncateID truncates an ID string (like UUIDs) to a short form. Default length is 12 characters if not specified.
func TruncateMiddle ¶
TruncateMiddle truncates a string by removing the middle portion. Useful for file paths: "/Users/mark/.../file.go"
func TruncateOutput ¶
TruncateOutput truncates output text and trims whitespace. Convenience function for tool outputs and results.
func WordWrapIndent ¶
WordWrapIndent wraps text at width and adds a prefix indent to each line.
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" )