Documentation
¶
Overview ¶
Package render owns CLI presentation primitives: ANSI styling, the startup logo, and SBOM output spec parsing. Higher-level scan / diff / explain text rendering remains in the cli package for now (it depends on many cli-internal helpers); extracting it is tracked as follow-up work.
Index ¶
- Constants
- func BuildSubprojectSummary(manifests []output.ScanManifest) string
- func Diff(w io.Writer, payload output.DiffResponse) error
- func DiffManifestDisplayLabel(manifest output.DiffManifestResult) string
- func DiffMarkdown(w io.Writer, payload output.DiffResponse) error
- func DiffPackageDisplayName(pkg output.PackageRef) string
- func Explain(w io.Writer, target output.ExplainTargetResponse, ...) error
- func ExplainMarkdown(w io.Writer, payload output.ExplainResponse) error
- func PadRight(value string, width int) string
- func ParseOutputFormat(value string) (output.Format, sbom.Target, string, error)
- func RelationshipOrder(relationship string) int
- func SBOMTarget(format output.Format) (sbom.Target, bool)
- func Scan(g *sdk.Graph, registry *sdk.PackageRegistry, findings []sdk.Finding, ...) string
- func ScanGraphDisplayName(g *sdk.Graph, fallback string) string
- func ScanMarkdown(w io.Writer, payload output.ScanResponse) error
- func ScorecardHeadline(card *sdk.PackageScorecard) string
- func StartupLogo(w io.Writer)
- func StripANSI(value string) string
- func Style(value string, codes ...string) string
- func TruncateToWidth(value string, width int) string
- func ValueOrDash(value string) string
- func WhyTreeLines(paths []explain.Path) []string
- func Wrap(value, color string) string
- func WrapLines(lines []string, width int) []string
- func WrapTextLines(value string, width int) []string
- func WriteOutputDocument(stdout io.Writer, spec OutputSpec, document []byte) error
- type MarkdownReport
- type MarkdownSection
- type OutputSpec
Constants ¶
const ( Reset = "\x1b[0m" Black = "\x1b[30m" Red = "\x1b[31m" Green = "\x1b[32m" Yellow = "\x1b[33m" Blue = "\x1b[34m" Magenta = "\x1b[35m" Purple = "\x1b[38;5;141m" Orange = "\x1b[38;5;208m" Cyan = "\x1b[36m" White = "\x1b[37m" Gray = "\x1b[90m" Bold = "\x1b[1m" Dim = "\x1b[2m" BgBlue = "\x1b[44m" BgCyan = "\x1b[44m" BgBrand = "\x1b[48;2;232;155;92m" BgNeutral = "\x1b[100m" BgGreen = "\x1b[42m" BgRed = "\x1b[41m" BgYellow = "\x1b[43m" BgMagenta = "\x1b[100m" )
ANSI escape sequences reused across cli text rendering and the interactive TUI.
Variables ¶
This section is empty.
Functions ¶
func BuildSubprojectSummary ¶ added in v0.14.0
func BuildSubprojectSummary(manifests []output.ScanManifest) string
BuildSubprojectSummary returns a human-readable line like "Discovered 2 subprojects: web (npm), api (go)" from the scan manifests. Returns "" when no named subprojects are present (e.g. single-root repos).
func Diff ¶
func Diff(w io.Writer, payload output.DiffResponse) error
Diff writes the compact human-readable diff report for the diff command.
func DiffManifestDisplayLabel ¶
func DiffManifestDisplayLabel(manifest output.DiffManifestResult) string
DiffManifestDisplayLabel returns a human-readable label for a manifest in diff output.
func DiffMarkdown ¶
func DiffMarkdown(w io.Writer, payload output.DiffResponse) error
DiffMarkdown writes a GitHub-flavored Markdown diff report.
func DiffPackageDisplayName ¶
func DiffPackageDisplayName(pkg output.PackageRef) string
DiffPackageDisplayName returns a human-readable label for a package.
func Explain ¶
func Explain(w io.Writer, target output.ExplainTargetResponse, includeReachabilityValue ...bool) error
Explain writes the compact human-readable explain report for one target dependency.
func ExplainMarkdown ¶
func ExplainMarkdown(w io.Writer, payload output.ExplainResponse) error
ExplainMarkdown writes a GitHub-flavored Markdown explain report.
func PadRight ¶
PadRight pads value with spaces to width visible columns, truncating first if value is wider than width.
func ParseOutputFormat ¶
ParseOutputFormat normalizes a user-supplied output format string.
func RelationshipOrder ¶
RelationshipOrder returns a sort rank for the named dependency relationship (manifest, self, parent, ancestor, root, direct, transitive). Lower wins. Unknown relationships sort last.
func SBOMTarget ¶
SBOMTarget returns the SBOM encoder target for an SBOM output format.
func Scan ¶
func Scan(g *sdk.Graph, registry *sdk.PackageRegistry, findings []sdk.Finding, matcherStats []sdk.MatcherStats, enrichEnabled, auditEnabled, reachabilityEnabled bool, failOn []string, subprojectSummary string) string
Scan returns the compact human-readable text report for a scan command. failOn is the active fail-on constraint list from config; N/A-severity findings (e.g. unknown-license) are suppressed unless "any" is present. subprojectSummary is an optional pre-computed line like "Discovered 2 subprojects: web (npm), api (go)" shown before the package count.
func ScanGraphDisplayName ¶
ScanGraphDisplayName returns a label for the scan target derived from g's single root, or fallback when g has zero or multiple roots.
func ScanMarkdown ¶
func ScanMarkdown(w io.Writer, payload output.ScanResponse) error
ScanMarkdown writes a GitHub-flavored Markdown scan report.
func ScorecardHeadline ¶
func ScorecardHeadline(card *sdk.PackageScorecard) string
ScorecardHeadline renders a one-line summary suitable for a "Project posture: …" prefix. Example:
"8.2/10 github.com/ossf/scorecard (updated 2026-04-12, scorecard v5.0.0)"
Returns "" when card is nil so callers can branch cleanly.
func StartupLogo ¶
StartupLogo plays a brief Bomly logo animation when w is an attached TTY. On non-TTY writers (pipes, files), it is a silent no-op.
func TruncateToWidth ¶
TruncateToWidth shortens value to width visible columns, appending "..." when it had to truncate (unless width is too small to fit the ellipsis).
func ValueOrDash ¶
ValueOrDash returns "-" for blank input so report tables show a placeholder in empty cells.
func WhyTreeLines ¶
WhyTreeLines renders a why/explain dependency tree without highlighting.
func WrapLines ¶
WrapLines wraps each input line to width by hard-cutting at width visible columns (counted with ANSI escapes stripped). Empty lines are preserved.
func WrapTextLines ¶
WrapTextLines splits value into space-delimited words and packs them into lines no wider than width visible columns. Words longer than width are hard-cut. ANSI escape sequences in value are stripped before measuring.
func WriteOutputDocument ¶
func WriteOutputDocument(stdout io.Writer, spec OutputSpec, document []byte) error
WriteOutputDocument writes a generated document to spec.Path (or to stdout when spec.Path is empty).
Types ¶
type MarkdownReport ¶
type MarkdownReport[T any] struct { Title string Intro func(T) []string Sections []MarkdownSection[T] }
MarkdownReport describes the command-specific sections for a Markdown report.
type MarkdownSection ¶
MarkdownSection describes one command-specific section in a Markdown report.
type OutputSpec ¶
OutputSpec describes one parsed -o argument: an output format and the destination path (empty path means stdout).
func ParseOutputSpecs ¶
func ParseOutputSpecs(values []string) ([]OutputSpec, error)
ParseOutputSpecs parses one or more -o values of the form "<format>[=<path>]". At most one entry may target stdout (omitted path).
func (OutputSpec) IsSBOM ¶
func (s OutputSpec) IsSBOM() bool
IsSBOM reports whether this output is a standard SBOM artifact.