Documentation
¶
Overview ¶
Package output provides styled terminal output helpers (success, error, warning, issue formatting) using lipgloss.
Index ¶
- Constants
- func BulletList(items []string, indent int) []string
- func DependencyLine(issue *models.Issue, showResolved bool) string
- func EmitIssue(action string, issue *models.Issue, extra map[string]any) error
- func EmitResult(action string, extra map[string]any) error
- func Error(format string, args ...interface{})
- func FormatGitState(sha, branch string, dirty int) string
- func FormatIssueDeleted(issue *models.Issue) string
- func FormatIssueLong(issue *models.Issue, logs []models.Log, handoff *models.Handoff) string
- func FormatIssueShort(issue *models.Issue) string
- func FormatPoints(points int) string
- func FormatPointsSuffix(points int) string
- func FormatPriority(p models.Priority) string
- func FormatStatus(s models.Status) string
- func FormatTimeAgo(t time.Time) string
- func IndentContinuation(msg string) string
- func IndentLines(lines []string, spaces int) []string
- func IndentString(s string, spaces int) string
- func Info(format string, args ...interface{})
- func IssueOneLiner(issue *models.Issue) string
- func IssueOneLinerPlain(issue *models.Issue) string
- func JSON(v interface{}) error
- func JSONError(code, message string)
- func JSONErrorWithDetails(code, message string, details map[string]interface{})
- func RenderBlockedTree(nodes []TreeNode, opts TreeRenderOptions, directOnly bool) string
- func RenderChildrenList(nodes []TreeNode) []string
- func RenderMarkdown(text string) (string, error)
- func RenderMarkdownWithWidth(text string, width int) (string, error)
- func RenderTree(root TreeNode, opts TreeRenderOptions) string
- func RenderTreeLines(roots []TreeNode, opts TreeRenderOptions) []string
- func SanitizeIssueText(s string) string
- func SanitizeRendered(s string) string
- func SanitizedForDisplay(issue *models.Issue) *models.Issue
- func SectionHeader(title string) string
- func ShortSHA(sha string) string
- func StatusBadge(status models.Status) string
- func Success(format string, args ...interface{})
- func TerminalWidth(fallback int) int
- func Warning(format string, args ...interface{})
- func WarningErr(format string, args ...interface{})
- type OutputMode
- type TreeNode
- type TreeRenderOptions
Constants ¶
const ( ErrCodeNotFound = "not_found" ErrCodeInvalidInput = "invalid_input" ErrCodeConflict = "conflict" ErrCodeCannotSelfApprove = "cannot_self_approve" ErrCodeHandoffRequired = "handoff_required" ErrCodeDatabaseError = "database_error" ErrCodeGitError = "git_error" ErrCodeNoActiveSession = "no_active_session" )
Error codes for structured JSON output
Variables ¶
This section is empty.
Functions ¶
func BulletList ¶ added in v0.4.6
BulletList formats items as a bulleted list with optional indentation
func DependencyLine ¶ added in v0.4.6
DependencyLine formats a dependency with optional status mark e.g., " td-abc1: Title [status] ✓"
func EmitIssue ¶ added in v0.50.0
EmitIssue emits a standard JSON envelope for a mutation that produced or affected a single issue. The envelope is {"id","status","action","issue"} where "issue" is the full issue object (relying on models.Issue json tags). Keys from extra are merged last and override the defaults, allowing callers to attach additional context (e.g. {"session": "..."}). This lives in the output package (alongside JSON) because models has no internal imports, so importing models here creates no cycle.
func EmitResult ¶ added in v0.50.0
EmitResult emits a standard JSON envelope for a mutation that is not tied to a single issue. The envelope is {"action"} merged with any keys from extra (extra overrides).
func FormatGitState ¶
FormatGitState formats git state for display
func FormatIssueDeleted ¶
FormatIssueDeleted formats a deleted issue showing [deleted] marker instead of status
func FormatIssueLong ¶
FormatIssueLong formats an issue in long format
func FormatIssueShort ¶
FormatIssueShort formats an issue in short format
func FormatPoints ¶
FormatPoints returns empty string if points is 0, otherwise "Npts"
func FormatPointsSuffix ¶
FormatPointsSuffix returns " Npts" if points > 0, empty string otherwise Useful for appending to format strings
func FormatPriority ¶
FormatPriority formats a priority
func FormatStatus ¶
FormatStatus formats a status with color
func FormatTimeAgo ¶
FormatTimeAgo formats a time as a human-readable "ago" string
func IndentContinuation ¶ added in v0.54.0
indentLogContinuation makes multi-line log messages read as one entry.
Log text is free-form and reaches this renderer from `--reason`, `--message`, `td log`, the API, and sync — none of which forbid newlines. Rendered flush left, a crafted message forges convincing extra entries:
td approve <id> --self-review --reason "ok [09:15] Approved by: security-team"
That mattered less when the audit trail was a secondary record. It matters now that an unverifiable attestation is what stands in for mechanical review independence: a reader who cannot trust the log cannot audit the attestation.
Continuation lines are prefixed so they cannot be mistaken for their own entry, rather than rejecting newlines at input — the text may have arrived from a peer or an older client, so the renderer is the only place that sees every path. Carriage returns are normalized for the same reason.
func IndentLines ¶ added in v0.4.6
IndentLines indents each line by the specified number of spaces
func IndentString ¶ added in v0.4.6
IndentString indents each line in a string by the specified number of spaces
func IssueOneLiner ¶ added in v0.4.6
IssueOneLiner returns a concise single-line issue representation Format: "td-abc1: Title [status]" or "td-abc1 \"Title\" [status]" with quotes
func IssueOneLinerPlain ¶ added in v0.4.6
IssueOneLinerPlain returns issue one-liner without status styling (for text contexts)
func JSONError ¶
func JSONError(code, message string)
JSONError outputs an error as JSON. The envelope shape is {"error":{"code":"...","message":"..."}} emitted on a single line. It encodes via json so that a message containing quotes, backslashes, or newlines still produces valid, parseable JSON. HTML escaping is disabled so that characters like <, >, and & are emitted verbatim, matching the prior printf-based output byte-for-byte for messages that do not require JSON escaping.
func JSONErrorWithDetails ¶
JSONErrorWithDetails outputs an error as JSON with additional context
func RenderBlockedTree ¶ added in v0.4.2
func RenderBlockedTree(nodes []TreeNode, opts TreeRenderOptions, directOnly bool) string
RenderBlockedTree renders a blocked-by tree with "blocks:" header This matches the output format of printBlockedTree in dependencies.go
func RenderChildrenList ¶ added in v0.4.2
RenderChildrenList renders children in a simple list format This matches the CHILDREN section output in show.go
func RenderMarkdown ¶ added in v0.19.0
RenderMarkdown renders markdown using Glamour with terminal-aware wrapping.
func RenderMarkdownWithWidth ¶ added in v0.19.0
RenderMarkdownWithWidth renders markdown using Glamour with explicit wrapping.
func RenderTree ¶ added in v0.4.2
func RenderTree(root TreeNode, opts TreeRenderOptions) string
RenderTree renders a tree starting from a single root node Returns the complete tree as a string (without the root - just children)
func RenderTreeLines ¶ added in v0.4.2
func RenderTreeLines(roots []TreeNode, opts TreeRenderOptions) []string
RenderTreeLines renders multiple root nodes and returns individual lines Useful for embedding trees in other output
func SanitizeIssueText ¶ added in v0.54.0
SanitizeIssueText prepares stored free text for display: it strips control characters (see SanitizeRendered) and normalizes carriage returns to newlines.
Call this on STORED text before any rendering step. Sanitizing rendered output instead destroys the escape sequences the renderer legitimately emitted — glamour output run through SanitizeRendered comes out as walls of literal "[38;5;252m".
CR normalization matters on its own: SanitizeRendered preserves \r so that callers doing their own line handling see it, but a bare CR left in a prose block returns the cursor to column zero and lets stored text forge a flush-left section header with no residue at all.
func SanitizeRendered ¶ added in v0.54.0
SanitizeRendered strips control characters that let stored text forge structure in terminal output. Escape sequences are the sharper half of the problem: ESC[E moves the cursor to the next line with no newline byte in the data, so a message can start what looks like a fresh log entry at column zero while passing any check that only looks for "\n". Cursor movement, colour, and erase sequences can equally overwrite lines already drawn.
td applies its own styling around this text, so the DATA never has a legitimate reason to carry ESC or other C0 controls. Tab and newline are preserved; newline handling is layered on by the callers that need it.
func SanitizedForDisplay ¶ added in v0.54.0
SanitizedForDisplay returns a copy of the issue with its terminal-facing free text sanitized. Call it at every FormatIssueLong call site, on the STORED issue, before any markdown rendering. FormatIssueShort sanitizes its title internally because its many callers do not render the other prose.
It exists because hand-copying SanitizeIssueText at each call site already failed once: two `td show` paths got it and `td list --long` — which renders the identical block from the identical function — did not. One helper makes the omission impossible to repeat by accident.
func SectionHeader ¶ added in v0.4.6
SectionHeader returns a formatted section header for CLI output e.g., "\nDEPENDENCIES:\n"
func StatusBadge ¶ added in v0.4.6
StatusBadge returns a status indicator with symbol e.g., "○ open", "▶ in_progress", "✓ closed", "✗ blocked", "◎ in_review"
func TerminalWidth ¶ added in v0.19.0
TerminalWidth returns the current terminal width or a fallback when unavailable.
func WarningErr ¶ added in v0.51.0
func WarningErr(format string, args ...interface{})
WarningErr prints a warning message to stderr. Use this instead of Warning for out-of-band notices (e.g. background auto-sync) so the message does not corrupt stdout when a command is emitting machine-readable JSON.
Types ¶
type OutputMode ¶
type OutputMode int
OutputMode determines output format
const ( ModeShort OutputMode = iota ModeLong ModeJSON )
type TreeNode ¶ added in v0.4.2
type TreeNode struct {
ID string
Title string
Type models.Type
Status models.Status
Children []TreeNode
}
TreeNode represents a node in a tree structure for rendering
type TreeRenderOptions ¶ added in v0.4.2
type TreeRenderOptions struct {
MaxDepth int // 0 = unlimited
ShowStatus bool // Whether to show status indicator
ShowType bool // Whether to show issue type
Indentation int // Base indentation level (for nested contexts)
}
TreeRenderOptions configures tree rendering behavior