output

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package output provides styled terminal output helpers (success, error, warning, issue formatting) using lipgloss.

Index

Constants

View Source
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

func BulletList(items []string, indent int) []string

BulletList formats items as a bulleted list with optional indentation

func DependencyLine added in v0.4.6

func DependencyLine(issue *models.Issue, showResolved bool) string

DependencyLine formats a dependency with optional status mark e.g., " td-abc1: Title [status] ✓"

func EmitIssue added in v0.50.0

func EmitIssue(action string, issue *models.Issue, extra map[string]any) error

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

func EmitResult(action string, extra map[string]any) error

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 Error

func Error(format string, args ...interface{})

Error prints an error message to stderr. It is a diagnostic about the command, never the command's result, and it is frequently printed on the same path that then emits a JSON error envelope on stdout — printing both to stdout leaves a --json caller with unparseable output. A terminal user sees no difference: stderr is unbuffered and interleaved on a tty.

func FormatGitState

func FormatGitState(sha, branch string, dirty int) string

FormatGitState formats git state for display

func FormatIssueDeleted

func FormatIssueDeleted(issue *models.Issue) string

FormatIssueDeleted formats a deleted issue showing [deleted] marker instead of status

func FormatIssueLong

func FormatIssueLong(issue *models.Issue, logs []models.Log, handoff *models.Handoff) string

FormatIssueLong formats an issue in long format

func FormatIssueShort

func FormatIssueShort(issue *models.Issue) string

FormatIssueShort formats an issue in short format

func FormatPoints

func FormatPoints(points int) string

FormatPoints returns empty string if points is 0, otherwise "Npts"

func FormatPointsSuffix

func FormatPointsSuffix(points int) string

FormatPointsSuffix returns " Npts" if points > 0, empty string otherwise Useful for appending to format strings

func FormatPriority

func FormatPriority(p models.Priority) string

FormatPriority formats a priority

func FormatStatus

func FormatStatus(s models.Status) string

FormatStatus formats a status with color

func FormatTimeAgo

func FormatTimeAgo(t time.Time) string

FormatTimeAgo formats a time as a human-readable "ago" string

func IndentContinuation added in v0.54.0

func IndentContinuation(msg string) string

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

func IndentLines(lines []string, spaces int) []string

IndentLines indents each line by the specified number of spaces

func IndentString added in v0.4.6

func IndentString(s string, spaces int) string

IndentString indents each line in a string by the specified number of spaces

func Info

func Info(format string, args ...interface{})

Info prints an info message to stdout. Unlike Error and Warning, Info's content is primary output — "No boards found" is the literal answer to `td board list`, and moving it to stderr would empty stdout for a command that succeeded. Info is the one of these four where a stderr move would be a new bug rather than a fix, so it stays put; anything genuinely out-of-band should call Warning instead.

func IssueOneLiner added in v0.4.6

func IssueOneLiner(issue *models.Issue) string

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

func IssueOneLinerPlain(issue *models.Issue) string

IssueOneLinerPlain returns issue one-liner without status styling (for text contexts)

func JSON

func JSON(v interface{}) error

JSON outputs data as JSON

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

func JSONErrorWithDetails(code, message string, details map[string]interface{})

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

func RenderChildrenList(nodes []TreeNode) []string

RenderChildrenList renders children in a simple list format This matches the CHILDREN section output in show.go

func RenderMarkdown added in v0.19.0

func RenderMarkdown(text string) (string, error)

RenderMarkdown renders markdown using Glamour with terminal-aware wrapping.

func RenderMarkdownWithWidth added in v0.19.0

func RenderMarkdownWithWidth(text string, width int) (string, error)

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

func SanitizeIssueText(s string) string

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

func SanitizeRendered(s string) string

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

func SanitizedForDisplay(issue *models.Issue) *models.Issue

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

func SectionHeader(title string) string

SectionHeader returns a formatted section header for CLI output e.g., "\nDEPENDENCIES:\n"

func ShortSHA

func ShortSHA(sha string) string

ShortSHA safely shortens a git SHA to 7 characters or returns as-is if shorter

func StatusBadge added in v0.4.6

func StatusBadge(status models.Status) string

StatusBadge returns a status indicator with symbol e.g., "○ open", "▶ in_progress", "✓ closed", "✗ blocked", "◎ in_review"

func Success

func Success(format string, args ...interface{})

Success prints a success message. This is the human-mode RESULT of a mutation — the counterpart of the JSON envelope emitted on the --json path, and normally in the sibling branch of the same if/else. It stays on stdout: a user running `td add ... > out.txt` expects the confirmation in the file, and moving it would hide the command's own answer from anyone reading stdout. It is not a diagnostic.

func TerminalWidth added in v0.19.0

func TerminalWidth(fallback int) int

TerminalWidth returns the current terminal width or a fallback when unavailable.

func Warning

func Warning(format string, args ...interface{})

Warning prints a warning message to stderr, for the same reason as Error: a warning annotates the command, it is not what the command was asked to produce. (This function used to print to stdout, which is why a separate WarningErr existed; now that Warning itself is safe, WarningErr is gone and its call sites use Warning.)

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

Jump to

Keyboard shortcuts

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