Documentation
¶
Overview ¶
Package output provides formatters for rendering service results as text tables or JSON.
Index ¶
- func DefangDomain(s string) string
- func DefangIP(s string) string
- func DefangURL(s string) string
- func NewGroupedWrappingTable(w io.Writer, minWidth, overhead int) *tablewriter.Table
- func NewGroupedWrappingTablePerCol(w io.Writer, colMaxWidths map[int]int) *tablewriter.Table
- func NewWrappingTable(w io.Writer, minWidth, overhead int) *tablewriter.Table
- func ResolveDefang(papLevel pap.Level, format Format, explicitDefang, noDefang bool) bool
- func StripANSI(s string) string
- func TerminalWidth(w io.Writer) int
- func Write(w io.Writer, format Format, result any) error
- type DefangWriter
- type Format
- type TableFormattable
- type TextFormattable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefangDomain ¶
DefangDomain replaces all dots in a domain name with [.] to prevent clickable links in reports. Example: "example.com" → "example[.]com".
func DefangIP ¶
DefangIP defangs an IP address string. IPv4: replaces dots with [.]. Example: "1.2.3.4" → "1[.]2[.]3[.]4". IPv6: wraps the address in brackets. Example: "::1" → "[::1]". Non-IP strings are returned unchanged.
func DefangURL ¶
DefangURL defangs a URL by replacing the scheme and dots in the host. Example: "http://example.com/path" → "hxxp://example[.]com/path". "https://foo.bar" → "hxxps://foo[.]bar". Non-URL strings (no "://") have all dots replaced.
func NewGroupedWrappingTable ¶
func NewGroupedWrappingTable(w io.Writer, minWidth, overhead int) *tablewriter.Table
NewGroupedWrappingTable returns a tablewriter that groups rows by the first column (merged cells), draws separator lines between groups, and auto-wraps content to fit the terminal. Use this for services that output typed records (e.g. DNS). minWidth and overhead behave the same as in NewWrappingTable.
func NewGroupedWrappingTablePerCol ¶ added in v0.4.0
NewGroupedWrappingTablePerCol is like NewGroupedWrappingTable but accepts explicit per-column max widths instead of a single global cap. colMaxWidths maps column index (0-based) to max character width; omit a column or set it to 0 to leave it unconstrained.
func NewWrappingTable ¶
func NewWrappingTable(w io.Writer, minWidth, overhead int) *tablewriter.Table
NewWrappingTable returns a tablewriter that auto-wraps cell content to fit the terminal. minWidth is the floor for the computed column max width; overhead is the characters consumed by borders, padding, and fixed columns.
func ResolveDefang ¶
ResolveDefang determines whether output should be defanged given the current flags and PAP level.
Rules:
- --no-defang (noDefang=true): always returns false regardless of other flags.
- --defang (explicitDefang=true): always returns true for every format, including JSON.
- PAP=AMBER or PAP=RED without --no-defang: returns true for text/plain formats; JSON stays raw because downstream consumers want unmodified data.
- Default (PAP=WHITE, no flags): returns false.
noDefang and explicitDefang are mutually exclusive; callers must validate this before calling ResolveDefang.
func TerminalWidth ¶
TerminalWidth returns the terminal width for w, or defaultTermWidth if w is not a terminal or the width cannot be determined.
Types ¶
type DefangWriter ¶
DefangWriter wraps an io.Writer and applies defanging transforms on every Write call. It replaces dots in domain-like and IP-like patterns, and defangs http/https schemes.
type TableFormattable ¶ added in v0.3.0
TableFormattable results know how to render themselves as an ASCII table.
type TextFormattable ¶
TextFormattable results know how to render themselves as plain text (one record per line). Used for piping output to other tools.