display

package
v3.15.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accent

func Accent(term *Terminal, text string) string

Accent renders accent-colored text.

func Bar

func Bar(term *Terminal, filled, total, width int) string

Bar renders a visual progress bar like ████████░░

func Bold

func Bold(term *Terminal, text string) string

Bold renders bold text.

func BulletList

func BulletList(term *Terminal, items []string) string

BulletList renders a bullet-point list.

func CheckMark

func CheckMark(term *Terminal) string

CheckMark renders a green checkmark.

func CountHeader

func CountHeader(term *Terminal, count int, noun string) string

CountHeader renders a "Found N items" header with an optional qualifier.

func CrossMark

func CrossMark(term *Terminal) string

CrossMark renders a red cross.

func Divider

func Divider(term *Terminal) string

Divider renders a subtle horizontal line.

func ErrorStyle

func ErrorStyle(term *Terminal, text string) string

ErrorStyle renders red text.

func FormatDuration

func FormatDuration(seconds int) string

FormatDuration converts seconds into a human-readable duration string.

func FormatFloat

func FormatFloat(f float64, decimals int) string

FormatFloat formats a float with specified decimal places.

func FormatNumber

func FormatNumber(n int) string

FormatNumber adds comma separators to an integer (e.g., 1234567 → "1,234,567").

func Header(term *Terminal, text string) string

Header renders a bold accent-colored section header.

func KeyValue

func KeyValue(term *Terminal, pairs []KVPair) string

KeyValue renders aligned key-value pairs. An empty Key creates a blank separator line between groups.

func KeyValueCompact

func KeyValueCompact(term *Terminal, pairs []KVPair) string

KeyValueCompact renders key-value pairs with minimal spacing.

func Label

func Label(term *Terminal, text string) string

Label renders dimmed label text.

func Max

func Max(a, b int) int

Max returns the larger of two ints.

func Min

func Min(a, b int) int

Min returns the smaller of two ints.

func Muted

func Muted(term *Terminal, text string) string

Muted renders dimmed text.

func NumberedList

func NumberedList(term *Terminal, items []string) string

NumberedList renders a numbered list (1-indexed).

func PadLeft

func PadLeft(s string, width int) string

PadLeft pads a string to the given width with spaces on the left.

func PadRight

func PadRight(s string, width int) string

PadRight pads a string to the given width with spaces.

func Paginator

func Paginator(term *Terminal, total, limit, offset int, hasMore bool) string

Paginator renders pagination info when there are more results.

func Percentage

func Percentage(n, total int) string

Percentage formats a ratio as percentage string.

func RelativeTime

func RelativeTime(unixSec int64) string

RelativeTime formats a Unix timestamp as relative time (e.g., "3 days ago").

func RenderAdvisories

func RenderAdvisories(data any, ctx *Context) string

RenderAdvisories renders advisory data.

func RenderAffected

func RenderAffected(data any, ctx *Context) string

RenderAffected renders affected products/packages.

func RenderCloudLocators

func RenderCloudLocators(data any, ctx *Context) string

RenderCloudLocators renders cloud resource locator templates.

func RenderCweGuidance

func RenderCweGuidance(data any, ctx *Context) string

RenderCweGuidance renders CWE-based guidance.

func RenderEcosystems

func RenderEcosystems(ecosystems []any, ctx *Context) string

RenderEcosystems renders the ecosystems list.

func RenderExploitSearch

func RenderExploitSearch(data any, ctx *Context) string

RenderExploitSearch renders exploit search results.

func RenderExploits

func RenderExploits(data any, ctx *Context) string

RenderExploits renders exploit data for a vulnerability. Handles both: exploits[] array present (pro) and summary-only (community).

func RenderFixes

func RenderFixes(data any, ctx *Context) string

RenderFixes renders fix data for a vulnerability.

func RenderGenericMap

func RenderGenericMap(data any, ctx *Context) string

RenderGenericMap renders any map data with intelligent formatting. Used as fallback for commands without specific renderers.

func RenderIdentifiers

func RenderIdentifiers(data any, ctx *Context, title string) string

RenderIdentifiers renders a list of CVE identifiers.

func RenderKev

func RenderKev(data any, ctx *Context) string

RenderKev renders CISA KEV data.

func RenderPackageVulns

func RenderPackageVulns(data any, ctx *Context) string

RenderPackageVulns renders package vulnerability list.

func RenderPackagesSearch

func RenderPackagesSearch(data any, ctx *Context) string

RenderPackagesSearch renders package search results with vuln/version counts.

func RenderProductVersions

func RenderProductVersions(data any, ctx *Context) string

RenderProductVersions renders product version list.

func RenderRemediationPlan

func RenderRemediationPlan(data any, ctx *Context) string

RenderRemediationPlan renders a remediation plan.

func RenderScorecard

func RenderScorecard(data any, ctx *Context) string

RenderScorecard renders a vulnerability scorecard.

func RenderScorecardSearch

func RenderScorecardSearch(data any, ctx *Context) string

RenderScorecardSearch renders scorecard search results.

func RenderSimpleList

func RenderSimpleList(data any, ctx *Context, noun string) string

RenderSimpleList renders a generic list of items from a map response. Looks for common patterns: items[], results[], data[], or the top-level array. RenderSimpleList renders a generic list with name/count from common list keys.

func RenderStatus

func RenderStatus(data any, ctx *Context) string

RenderStatus renders VDB status/health information.

func RenderSummary

func RenderSummary(data any, ctx *Context) string

RenderSummary renders the VDB database summary.

func RenderTimeline

func RenderTimeline(data any, ctx *Context) string

RenderTimeline renders vulnerability timeline events.

func RenderTrafficFilters

func RenderTrafficFilters(data any, ctx *Context) string

RenderTrafficFilters renders IDS/IPS traffic filter rules (Snort).

func RenderVersions

func RenderVersions(data any, ctx *Context) string

RenderVersions renders package version list.

func RenderVulnDetail

func RenderVulnDetail(data any, ctx *Context) string

RenderVulnDetail renders a single vulnerability detail view. Handles both flat vuln objects and CVE 5.0 JSON format (array of records with containers/cveMetadata).

func RenderWorkarounds

func RenderWorkarounds(data any, ctx *Context) string

RenderWorkarounds renders workaround information.

func RoundFloat

func RoundFloat(f float64, n int) float64

RoundFloat rounds a float to n decimal places.

func SeverityBadge

func SeverityBadge(term *Terminal, level string) string

SeverityBadge renders an inline colored severity label.

func SeverityText

func SeverityText(term *Terminal, level string) string

SeverityText renders severity text with the appropriate color (no background).

func ShortDivider

func ShortDivider(term *Terminal, width int) string

ShortDivider renders a shorter divider for subsections.

func Subheader

func Subheader(term *Terminal, text string) string

Subheader renders a bold section subheader.

func Success

func Success(term *Terminal, text string) string

Success renders green text.

func Table

func Table(term *Terminal, cols []Column, rows [][]string) string

Table renders a responsive table without borders. Uses spacing and alignment for visual separation, with bold headers and a thin separator.

func Teal

func Teal(term *Terminal, text string) string

Teal renders teal-colored text. Used to highlight file paths in scan output.

func ToFloat64

func ToFloat64(v any) float64

ToFloat64 converts a JSON-decoded number to float64.

func ToIntVal

func ToIntVal(v any) int

ToIntVal converts a JSON-decoded number (float64 or int) to int for display.

func ToMap

func ToMap(v any) map[string]any

ToMap converts a typed struct to map[string]any via JSON round-trip. Useful when renderers expect map data but commands have typed structs.

func ToStringVal

func ToStringVal(v any) string

ToStringVal extracts a string from an interface value.

func Truncate

func Truncate(s string, max int) string

Truncate truncates a string to max length with ellipsis.

func WarningMark

func WarningMark(term *Terminal) string

WarningMark renders a yellow warning indicator.

Types

type Alignment

type Alignment int

Alignment controls column text alignment.

const (
	AlignLeft Alignment = iota
	AlignRight
)

type Column

type Column struct {
	Header   string
	Width    int                 // 0 = auto-calculate
	MinWidth int                 // minimum width when auto-calculating
	MaxWidth int                 // maximum width when auto-calculating (0 = unlimited)
	Align    Alignment           // left or right alignment
	Color    func(string) string // optional per-cell coloring function
}

Column defines a table column.

type Context

type Context struct {
	Logger     *Logger
	Term       *Terminal
	Mode       OutputMode
	Silent     bool
	NoProgress bool
}

Context bundles display capabilities for a command.

func FromCommand

func FromCommand(cmd *cobra.Command) *Context

FromCommand retrieves the display context from a cobra command. Returns a default text-mode context if none was attached.

func New

func New(mode OutputMode, silent bool) *Context

New creates a display context from mode and silent flag.

func NewFromFlags

func NewFromFlags(output string, silent bool) *Context

NewFromFlags creates a display context from string output flag and silent bool.

func NewWithProgress added in v3.11.0

func NewWithProgress(mode OutputMode, silent bool, noProgress bool) *Context

NewWithProgress creates a display context from output and progress flags.

func (*Context) Attach

func (c *Context) Attach(cmd *cobra.Command)

Attach stores the display context in a cobra command's context.

func (*Context) IsJSON

func (c *Context) IsJSON() bool

IsJSON returns true if output mode is JSON.

func (*Context) Progress added in v3.11.0

func (c *Context) Progress(title string, total int) *Progress

Progress creates and starts a progress activity. When progress is disabled, the returned object is a no-op and is safe to use unconditionally.

func (*Context) Render

func (c *Context) Render(data interface{}, textFn func(data interface{}, ctx *Context) string) error

Render outputs data as JSON (in JSON mode) or calls the text renderer. The text renderer receives data and the context, and returns a string.

type KVPair

type KVPair struct {
	Key        string
	Value      string
	ValueStyle func(string) string // optional styling for the value
}

KVPair represents a key-value pair for display.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger routes output between stdout and stderr based on mode and silent flags.

func NewLogger

func NewLogger(mode OutputMode, silent bool, term *Terminal) *Logger

NewLogger creates a logger with the given mode and silent flag.

func (*Logger) Error

func (l *Logger) Error(msg string)

Error prints an error to stderr. Never suppressed.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf prints a formatted error to stderr.

func (*Logger) Info

func (l *Logger) Info(msg string)

Info prints an informational message to stderr. Suppressed when silent.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof prints a formatted informational message to stderr.

func (*Logger) Result

func (l *Logger) Result(s string)

Result prints the final text result to stdout.

func (*Logger) ResultJSON

func (l *Logger) ResultJSON(data interface{}) error

ResultJSON encodes data as indented JSON to stdout.

func (*Logger) Status

func (l *Logger) Status(msg string)

Status prints a status/progress message to stderr. Suppressed when silent.

func (*Logger) Statusf

func (l *Logger) Statusf(format string, args ...interface{})

Statusf prints a formatted status message to stderr.

func (*Logger) Warn

func (l *Logger) Warn(msg string)

Warn prints a warning to stderr. Suppressed when silent.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf prints a formatted warning to stderr.

type OutputMode

type OutputMode int

OutputMode determines how output is routed.

const (
	ModeText OutputMode = iota
	ModeJSON
)

type Progress added in v3.11.0

type Progress struct {
	// contains filtered or unexported fields
}

Progress renders one transparent activity line on stderr. A progress activity has a static title, a numeric done/total goal, and a stage title that can change while work proceeds inside the current stage.

func (*Progress) Advance added in v3.11.0

func (p *Progress) Advance(stage string)

Advance moves progress forward by one unit and updates the stage title.

func (*Progress) Complete added in v3.11.0

func (p *Progress) Complete(stage string)

Complete finalizes the activity with a success line.

func (*Progress) Fail added in v3.11.0

func (p *Progress) Fail(stage string)

Fail finalizes the activity with a failure line.

func (*Progress) Interactive added in v3.11.0

func (p *Progress) Interactive() bool

Interactive reports whether progress is rendering as a live TTY line.

func (*Progress) SetStage added in v3.11.0

func (p *Progress) SetStage(stage string)

SetStage changes the current stage title without changing numeric progress.

func (*Progress) Update added in v3.11.0

func (p *Progress) Update(done int, stage string)

Update sets the numeric progress and, when non-empty, the current stage.

func (*Progress) Writer added in v3.13.1

func (p *Progress) Writer(w io.Writer) io.Writer

Writer returns a writer that can be used for ordinary log output while this progress activity is active. On interactive terminals it clears the live progress row before writing and redraws it afterwards, so log lines do not leave behind duplicate progress bars.

type Terminal

type Terminal struct {
	Width        int
	Height       int
	IsTTY        bool // stdout is a terminal
	StderrTTY    bool
	ColorProfile termenv.Profile
}

Terminal holds detected terminal capabilities.

func NewTerminal

func NewTerminal() *Terminal

NewTerminal detects terminal capabilities.

func (*Terminal) HasColor

func (t *Terminal) HasColor() bool

HasColor returns true if the terminal supports color output.

func (*Terminal) LipglossRenderer

func (t *Terminal) LipglossRenderer() *lipgloss.Renderer

LipglossRenderer returns a lipgloss renderer configured for this terminal.

func (*Terminal) Refresh

func (t *Terminal) Refresh()

Refresh re-reads terminal dimensions.

Jump to

Keyboard shortcuts

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