output

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package output provides formatters for rendering service results as text tables or JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefangDomain

func DefangDomain(s string) string

DefangDomain replaces all dots in a domain name with [.] to prevent clickable links in reports. Example: "example.com" → "example[.]com".

func DefangIP

func DefangIP(s string) string

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

func DefangURL(s string) string

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

func NewGroupedWrappingTablePerCol(w io.Writer, colMaxWidths map[int]int) *tablewriter.Table

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

func ResolveDefang(papLevel pap.Level, format Format, explicitDefang, noDefang bool) bool

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 StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape sequences from external data before terminal output.

func TerminalWidth

func TerminalWidth(w io.Writer) int

TerminalWidth returns the terminal width for w, or defaultTermWidth if w is not a terminal or the width cannot be determined.

func Write

func Write(w io.Writer, format Format, result any) error

Write dispatches a service result to the appropriate formatter. JSON uses json.Encoder with indentation. Table requires the result to implement TableFormattable. Text requires the result to implement TextFormattable.

Types

type DefangWriter

type DefangWriter struct {
	Inner io.Writer
}

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.

func (*DefangWriter) Write

func (d *DefangWriter) Write(p []byte) (n int, err error)

Write implements io.Writer; it defangs p before forwarding to the inner writer.

type Format

type Format string

Format is the output format requested by the user.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatText  Format = "text"
)

Output format constants supported by the --output flag.

type TableFormattable added in v0.3.0

type TableFormattable interface {
	WriteTable(w io.Writer) error
}

TableFormattable results know how to render themselves as an ASCII table.

type TextFormattable

type TextFormattable interface {
	WriteText(w io.Writer) error
}

TextFormattable results know how to render themselves as plain text (one record per line). Used for piping output to other tools.

Jump to

Keyboard shortcuts

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