Documentation
¶
Overview ¶
Package formatter provides output formatting interfaces and implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatMaxHosts ¶
FormatMaxHosts returns a human-readable string for max hosts. Caps display at a readable threshold for very large IPv6 networks.
func FormatNetworkSummary ¶
func FormatNetworkSummary(info NetworkInfo) string
FormatNetworkSummary formats a NetworkInfo as styled text. This is shared between TableFormatter and TextFormatter.
func FormatNumber ¶ added in v1.0.1
FormatNumber formats a non-negative integer with comma thousand separators (e.g., 1234 becomes "1,234").
Types ¶
type Config ¶
type Config struct {
Format OutputFormat
Width int // Terminal width for table formatting
PrettyPrint bool // Pretty print JSON output
}
Config holds configuration options for formatter creation.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Formatter ¶
type Formatter interface {
// FormatNetwork formats a single network's information.
FormatNetwork(n subnet.Network) (string, error)
// FormatSubnets formats a network with its subnets.
FormatSubnets(n subnet.Network) (string, error)
}
Formatter defines the interface for formatting network information.
type JSONFormatter ¶
type JSONFormatter struct {
Indent bool
}
JSONFormatter formats network information as JSON.
func NewJSONFormatter ¶
func NewJSONFormatter(indent bool) *JSONFormatter
NewJSONFormatter creates a new JSON formatter.
func (*JSONFormatter) FormatNetwork ¶
func (f *JSONFormatter) FormatNetwork(n subnet.Network) (string, error)
FormatNetwork formats a single network's information as JSON.
func (*JSONFormatter) FormatSubnets ¶
func (f *JSONFormatter) FormatSubnets(n subnet.Network) (string, error)
FormatSubnets formats a network with its subnets as JSON.
type NetworkInfo ¶
type NetworkInfo struct {
CIDR string
NetworkAddr string
BroadcastAddr string
FirstHostIP string
LastHostIP string
SubnetMask string
MaskBits int
MaxHosts string
}
NetworkInfo holds formatted network information for display.
func ToNetworkInfo ¶
func ToNetworkInfo(n subnet.Network) NetworkInfo
ToNetworkInfo converts a subnet.Network to formatted NetworkInfo for display.
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the available output format types.
const ( FormatJSON OutputFormat = "json" FormatTable OutputFormat = "table" FormatText OutputFormat = "text" // DefaultTerminalWidth is the default width used for table formatting // when no terminal width is detected. DefaultTerminalWidth = 120 )
type SubnetInfo ¶
type SubnetInfo struct {
CIDR string
SubnetMask string
FirstIP string
LastIP string
Broadcast string
Hosts string
}
SubnetInfo holds formatted subnet information for table display.
func ToSubnetInfo ¶
func ToSubnetInfo(n subnet.Network) SubnetInfo
ToSubnetInfo converts a subnet.Network to formatted SubnetInfo for table display.
func ToSubnetInfoSlice ¶
func ToSubnetInfoSlice(networks []subnet.Network) []SubnetInfo
ToSubnetInfoSlice converts a slice of subnet.Network to SubnetInfo.
type TableFormatter ¶
type TableFormatter struct {
// contains filtered or unexported fields
}
TableFormatter formats network information as styled tables.
func NewTableFormatter ¶
func NewTableFormatter(terminalWidth int) *TableFormatter
NewTableFormatter creates a new table formatter.
func (*TableFormatter) FormatNetwork ¶
func (f *TableFormatter) FormatNetwork(n subnet.Network) (string, error)
FormatNetwork formats a single network's information as a styled table.
func (*TableFormatter) FormatSubnets ¶
func (f *TableFormatter) FormatSubnets(n subnet.Network) (string, error)
FormatSubnets formats a network with its subnets as a styled table.
type TextFormatter ¶
type TextFormatter struct{}
TextFormatter formats network information as plain styled text.
func NewTextFormatter ¶
func NewTextFormatter() *TextFormatter
NewTextFormatter creates a new text formatter.
func (*TextFormatter) FormatNetwork ¶
func (f *TextFormatter) FormatNetwork(n subnet.Network) (string, error)
FormatNetwork formats a single network's information as styled text.
func (*TextFormatter) FormatSubnets ¶
func (f *TextFormatter) FormatSubnets(n subnet.Network) (string, error)
FormatSubnets formats a network with its subnets as styled text (simple list).