Documentation
¶
Index ¶
- Constants
- Variables
- func Banner(title string, badges ...string) string
- func Columns(width, gap int, panes ...Pane) string
- func Completions[T any](values []T, fields map[string]func(T) string, opts ...Options) []string
- func CompletionsStyled[T any](values []T, fields map[string]func(T) string, styleOf func(T) string, ...) (results []string)
- func Details[T any](value T, fields map[string]func(T) string, opts ...Options) string
- func Fmt(color string) string
- func FormatSmallID(id string) string
- func KVLines(pairs [][2]string) (lines []string)
- func StripANSI(s string) string
- func Table[T any](values []T, fields map[string]func(T) string, opts ...Options) *table.Table
- func VisibleWidth(s string) int
- type Detail
- type HeaderSet
- type Options
- type Pane
- type Section
Constants ¶
const ( Reset = "\x1b[0m" Bold = "\x1b[1m" Dim = "\x1b[2m" )
const ( SGRStart = "\x1b[" Fg = "38;05;" Bg = "48;05;" SGREnd = "m" )
Text effects.
Variables ¶
var ( AIMSDefault = table.Style{ Name: "AIMSDefault", Box: table.BoxStyle{ BottomLeft: " ", BottomRight: " ", BottomSeparator: " ", Left: " ", LeftSeparator: " ", MiddleHorizontal: "=", MiddleSeparator: " ", MiddleVertical: " ", PaddingLeft: " ", PaddingRight: " ", Right: " ", RightSeparator: " ", TopLeft: " ", TopRight: " ", TopSeparator: " ", UnfinishedRow: "~~", }, Color: table.ColorOptions{ IndexColumn: text.Colors{}, Footer: text.Colors{}, Header: text.Colors{}, Row: text.Colors{}, RowAlternate: text.Colors{}, }, Format: table.FormatOptions{ Footer: text.FormatDefault, Header: text.FormatTitle, Row: text.FormatDefault, }, Options: table.Options{ DrawBorder: false, SeparateColumns: true, SeparateFooter: false, SeparateHeader: true, SeparateRows: false, }, } AIMSBordersDefault = table.Style{ Name: "AIMSBordersDefault", Box: table.BoxStyle{ BottomLeft: "+", BottomRight: "+", BottomSeparator: "-", Left: "|", LeftSeparator: "+", MiddleHorizontal: "-", MiddleSeparator: "+", MiddleVertical: "|", PaddingLeft: " ", PaddingRight: " ", Right: "|", RightSeparator: "+", TopLeft: "+", TopRight: "+", TopSeparator: "-", UnfinishedRow: "~~", }, Color: table.ColorOptions{ IndexColumn: text.Colors{}, Footer: text.Colors{}, Header: text.Colors{}, Row: text.Colors{}, RowAlternate: text.Colors{}, }, Format: table.FormatOptions{ Footer: text.FormatDefault, Header: text.FormatTitle, Row: text.FormatDefault, }, Options: table.Options{ DrawBorder: true, SeparateColumns: true, SeparateFooter: false, SeparateHeader: true, SeparateRows: false, }, } )
var FgYellow = "\x1b[33m"
FgYellow is the one named text colour still used directly (the rest of the palette went through fatih/color); keep it alongside the SGR helpers below.
Functions ¶
func Banner ¶
Banner renders the one-line header of a single-object detail view: a title on the left and optional status badges on the right, joined by a dim " · ", followed by a dim horizontal rule. The title and badges are rendered verbatim — callers colour/bold them as they wish — so this only owns the shared mechanics (badge separator, spacing, rule). Empty badges are skipped. It is the shared header behind every domain's `info` view.
func Columns ¶
Columns arranges panes side by side, packing as many as fit within width (0 = detect the terminal), then wrapping to a new band below. A pane is never split; each is padded to its own widest line, and gap spaces separate adjacent panes. Layout is display-width aware, so ANSI escapes don't throw off alignment. This is the reusable primitive for "categories as columns" detail views (e.g. Identity | Provenance | Classification).
func Completions ¶
Completions returns (candidate, description) pairs for carapace.ActionValuesDescribed.
func CompletionsStyled ¶
func CompletionsStyled[T any](values []T, fields map[string]func(T) string, styleOf func(T) string, opts ...Options) (results []string)
CompletionsStyled is like Completions but also emits a per-candidate style, returning (candidate, description, style) triples for carapace.ActionStyledValuesDescribed. styleOf maps each source value to a carapace style string (e.g. style.Green); a nil styleOf yields empty styles. The candidate is inserted verbatim, so all values are ANSI-stripped here — colour comes from the returned style, never from embedded escape codes.
func Details ¶
Details is almost identical to Table and requires a type parameter for cmd/displaying an object with more details. The headers function parameter can either be one also used for cmd/displaying the type in a table, or another with different output for all/some of the fields. If the headers are weighted, a newline is left between each group of headers (grouped by weight).
func FormatSmallID ¶
FormatSmallID returns a smallened ID for table cmd/display.
func KVLines ¶
KVLines renders key/value pairs into aligned "key : value" detail lines: the key subdued (cyan) and right-aligned to the widest *shown* key, a dim " : " separator, then the value (which keeps its own colour). Pairs whose value is empty are skipped entirely, so callers can pass a fixed field list and let absent fields drop out. This is the shared line renderer behind the side-by-side info panes (see Pane / Columns), so every domain's detail view colours keys alike.
func StripANSI ¶
StripANSI removes ANSI SGR escape sequences (colour/style) from a string, returning plain text. Used to sanitize values destined for completion candidates/descriptions, which must be plain so they don't bleed colour or get inserted verbatim into the command line.
func Table ¶
TableWith requires a type parameter consisting of a type for which a corresponding map of "Column Field" to a function generating its table value exits, passed as the fields function argument. The values argument is the list of objects to be cmd/displayed in the table, with options.
func VisibleWidth ¶
VisibleWidth returns the number of visible columns a string occupies, ignoring ANSI SGR escape sequences (colour/style) and counting each remaining rune as one column. This is what makes column alignment correct for coloured content.
Types ¶
type Detail ¶
type Detail struct {
Title string // banner title, already coloured/bold by the domain
Badges []string // banner status badges, already coloured
Panes []Pane // side-by-side info columns; empty panes are dropped
Insights []string // derived observations, listed under an "Insights" header
Sections []Section // trailing titled blocks (scripts, etc.)
}
Detail is the assembled content of a single-object `info` view: a banner (title + badges), a row of side-by-side info panes, a derived-insights block, and any trailing sections. A domain supplies the pieces; Render lays them out identically everywhere, so every domain's detail view — credential, service, and the next guinea pig — shares one structure and one look.
Render returns the block with no trailing newline, mirroring Columns/Banner, so callers print it with fmt.Println (and a following fmt.Println for the blank separator between objects).
type HeaderSet ¶
type HeaderSet struct {
// contains filtered or unexported fields
}
HeaderSet accumulates weighted headers through a fluent Add, replacing the `add := func(name string, weight int){ headers = append(...) }` closure that every domain's DisplayHeaders / DisplayDetails / Completions used to re-declare. Start one with Headers().
func Headers ¶
func Headers() *HeaderSet
Headers begins a fluent header set:
return display.Headers().Add("ID", 1).Add("Name", 2).Options()
type Options ¶
type Options func(opts *opts) *opts
Options are functions allowing to customize or easily use table adjusment helpers.
func WithAutoSmallID ¶
func WithAutoSmallID() Options
WithAutoSmallID automatically truncates columns named "ID" to maximum 8 characters.
func WithCandidateValue ¶
WithCandidateValue sets the header name (field) to use as the completion candidate to be inserted for the given type.
func WithHeader ¶
WithHeader adds a specific header for the cmd/display using these options.
func WithSplitCandidate ¶
WithSplitCandidate will attempt to split the headers/fallbacks provided with WithCandidateValue() -if used-, and will generate aliased/non-aliased completions for each. This is useful when you don't use a unique ID with WithCandidateValue.
type Pane ¶
type Pane struct {
Title string // optional heading, rendered bold above Lines
Lines []string // content lines, already formatted
}
Pane is a titled block of pre-rendered content lines, laid out side by side with other panes by Columns. Lines may already contain ANSI colour/style; alignment accounts for that.
func NonEmptyPanes ¶
NonEmptyPanes returns the panes that have at least one content line, so a section with no data never prints a bare title. It is what lets a domain hand Render a fixed pane list and let the absent ones fall away.
type Section ¶
type Section struct {
Title string // bold heading, printed above Body
Body string // pre-rendered content, may be multi-line
}
Section is an optional titled block appended below the info panes of a detail view (e.g. a port's NSE scripts). A Section whose Body is blank is skipped; a Section with an empty Title prints its Body with no heading.