render

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

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

func PadRight(value string, width int) string

PadRight pads value with spaces to width visible columns, truncating first if value is wider than width.

func ParseOutputFormat

func ParseOutputFormat(value string) (output.Format, sbom.Target, string, error)

ParseOutputFormat normalizes a user-supplied output format string.

func RelationshipOrder

func RelationshipOrder(relationship string) int

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

func SBOMTarget(format output.Format) (sbom.Target, bool)

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

func ScanGraphDisplayName(g *sdk.Graph, fallback string) string

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(w io.Writer)

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 StripANSI

func StripANSI(value string) string

StripANSI removes any CSI escape sequences from value.

func Style

func Style(value string, codes ...string) string

Style applies one or more ANSI codes to value.

func TruncateToWidth

func TruncateToWidth(value string, width int) string

TruncateToWidth shortens value to width visible columns, appending "..." when it had to truncate (unless width is too small to fit the ellipsis).

func ValueOrDash

func ValueOrDash(value string) string

ValueOrDash returns "-" for blank input so report tables show a placeholder in empty cells.

func WhyTreeLines

func WhyTreeLines(paths []explain.Path) []string

WhyTreeLines renders a why/explain dependency tree without highlighting.

func Wrap

func Wrap(value, color string) string

Wrap returns value bracketed by the given color/style and a reset.

func WrapLines

func WrapLines(lines []string, width int) []string

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

func WrapTextLines(value string, width int) []string

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

type MarkdownSection[T any] struct {
	Title string
	Lines func(T) []string
}

MarkdownSection describes one command-specific section in a Markdown report.

type OutputSpec

type OutputSpec struct {
	Format output.Format
	Target sbom.Target
	Label  string
	Path   string
}

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.

Jump to

Keyboard shortcuts

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