Documentation
¶
Overview ¶
Package tui provides an interactive terminal user interface for subnet calculations. It uses Bubble Tea for the TUI framework and allows users to interactively split and join subnets, visualize subnet hierarchies, and export results as JSON.
Index ¶
- Constants
- func Run(cidr string, initialSplit int) error
- type ExportNode
- type Model
- type SubnetNode
- func (n *SubnetNode) BroadcastAddr() netip.Addr
- func (n *SubnetNode) CIDR() netip.Prefix
- func (n *SubnetNode) DeepCopy(parent *SubnetNode) *SubnetNode
- func (n *SubnetNode) ExportJSON() (string, error)
- func (n *SubnetNode) FirstIP() netip.Addr
- func (n *SubnetNode) Hosts() uint
- func (n *SubnetNode) Join() bool
- func (n *SubnetNode) LastIP() netip.Addr
- func (n *SubnetNode) Split() bool
- func (n *SubnetNode) SplitToDepth(targetBits int)
- func (n *SubnetNode) SubnetMask() netip.Addr
Constants ¶
const ( // MaxSplitDepth is the maximum prefix length for subnet splitting (e.g., /30). // Splitting beyond this depth is not allowed as /31 and /32 networks have no usable hosts. MaxSplitDepth = 30 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExportNode ¶
type ExportNode struct {
CIDR string `json:"cidr"` // Network in CIDR notation
FirstIP string `json:"firstIP"` // First usable host IP
LastIP string `json:"lastIP"` // Last usable host IP
BroadcastAddr string `json:"broadcastAddr"` // Broadcast address
SubnetMask string `json:"subnetMask"` // Subnet mask
Hosts uint `json:"hosts"` // Number of usable hosts
Children []*ExportNode `json:"children,omitempty"` // Child subnets if split
}
ExportNode is a JSON-serializable representation of a subnet node. It mirrors SubnetNode but uses string representations suitable for JSON output.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the Bubble Tea model for the interactive subnet TUI. It maintains the subnet tree state, cursor position, viewport dimensions, and UI components like help and status messages.
func NewModel ¶
NewModel creates a new TUI model from a CIDR string. Optional targetBits parameter specifies initial split depth (0 means no initial split).
type SubnetNode ¶
type SubnetNode struct {
Network subnet.Network // Network holds the subnet calculation details
Parent *SubnetNode // Parent node, nil for root
Children []*SubnetNode // Child subnets when split
IsSplit bool // Whether this node has been split
}
SubnetNode represents a node in the subnet tree hierarchy. Each node embeds network information and can be split into two child subnets or joined back with its sibling into the parent subnet.
func (*SubnetNode) BroadcastAddr ¶
func (n *SubnetNode) BroadcastAddr() netip.Addr
BroadcastAddr returns the broadcast address (last IP in range for IPv6).
func (*SubnetNode) CIDR ¶
func (n *SubnetNode) CIDR() netip.Prefix
CIDR returns the network prefix (e.g., 192.168.1.0/24).
func (*SubnetNode) DeepCopy ¶ added in v1.1.0
func (n *SubnetNode) DeepCopy(parent *SubnetNode) *SubnetNode
DeepCopy creates an independent deep copy of the subnet tree. The new tree has the same structure and Network values but separate memory, allowing modifications without affecting the original.
func (*SubnetNode) ExportJSON ¶
func (n *SubnetNode) ExportJSON() (string, error)
ExportJSON returns the subnet tree as a formatted JSON string. The output includes the full tree structure with all split children.
func (*SubnetNode) FirstIP ¶
func (n *SubnetNode) FirstIP() netip.Addr
FirstIP returns the first usable host IP address.
func (*SubnetNode) Hosts ¶
func (n *SubnetNode) Hosts() uint
Hosts returns the number of usable host addresses (capped at max uint for large IPv6 networks).
func (*SubnetNode) Join ¶
func (n *SubnetNode) Join() bool
Join merges all children back into this node, undoing any splits. Returns true if joined, false if the node was not split.
func (*SubnetNode) LastIP ¶
func (n *SubnetNode) LastIP() netip.Addr
LastIP returns the last usable host IP address.
func (*SubnetNode) Split ¶
func (n *SubnetNode) Split() bool
Split divides a subnet node into two child subnets by incrementing the prefix length. Returns true if the split was successful, false if already split or at max depth.
func (*SubnetNode) SplitToDepth ¶
func (n *SubnetNode) SplitToDepth(targetBits int)
SplitToDepth recursively splits the subnet until all leaves reach the target prefix length. For example, SplitToDepth(26) on a /24 creates four /26 subnets.
func (*SubnetNode) SubnetMask ¶
func (n *SubnetNode) SubnetMask() netip.Addr
SubnetMask returns the subnet mask as an address.