Documentation
¶
Overview ¶
Package tui implements the terminal user interface for graph visualization. It uses the Bubbletea framework to create an interactive TUI with support for pan, zoom, search, and theme switching. The implementation follows The Elm Architecture pattern with a Model-Update-View cycle.
Package tui implements cosmo-style rendering for graph visualization. Based on original TypeScript implementation from: https://github.com/turutupa/cosmo
COSMO RENDERING CONVENTIONS: ============================
Node Position:
- position.Y refers to the TOP of the VALUE frame (not the ID frame!)
- ID frame is rendered IDOffset (2) rows ABOVE the value frame
- Total node rendering spans from (position.Y - IDOffset) to (position.Y + FrameHeight)
Node Structure (5 lines total at position):
Y-2: ┌──────────────┐ (ID frame top) Y-1: │ node-id │ (ID frame middle) Y+0: ┌──────────────┐ (Value frame top - overwrites ID frame bottom) Y+1: │ node-value │ (Value frame middle - EDGE CONNECTION POINT) Y+2: └──────────────┘ (Value frame bottom)
Edge Connections:
- Edges connect at position.Y + 1 (center line of value frame)
- Use orthogonal routing with box-drawing characters (─│┌┐└┘)
Rendering Order:
- Edges first (background layer)
- Nodes second (foreground layer)
Layout Algorithm:
- Uses tree-based BFS layout (similar to ELK's mrtree)
- Nodes arranged in levels based on graph depth
- Horizontal spacing: 18 units, Vertical spacing: 8 units
Index ¶
- Constants
- func Run(g *graph.Graph, options ...ModelOption) error
- type Cell
- type CellStyle
- type FitViewMsg
- type HideMenuMsg
- type KeyMap
- type Model
- type ModelOption
- func WithAutoSelectFirst() ModelOption
- func WithAutoTheme() ModelOption
- func WithGraph(g *graph.Graph) ModelOption
- func WithInitialPan(x, y int) ModelOption
- func WithInitialZoom(zoom float64) ModelOption
- func WithKeyMap(keyMap KeyMap) ModelOption
- func WithLayoutDirection(direction layout.Direction) ModelOption
- func WithLayoutOptions(opts layout.LayoutOptions) ModelOption
- func WithOptions(options ...ModelOption) ModelOption
- func WithSelectedNode(nodeID string) ModelOption
- func WithStyles(styles *theme.Styles) ModelOption
- func WithTheme(themeName string) ModelOption
- type NodePositions
- type PanMsg
- type PathPoint
- type Position
- type QuitMsg
- type Screen
- type SearchMsg
- type SelectNodeMsg
- type ShowKeybindingsMsg
- type ShowMenuMsg
- type ShowSearchMsg
- type ThemeChangeMsg
- type WindowSizeMsg
- type ZoomMsg
Constants ¶
const ( DefaultNodeWidth = 16 // Width of node frames (inner content width) TotalNodeWidth = 18 // Total width including borders (DefaultNodeWidth + 2) FrameHeight = 5 // Height of complete node rendering (cosmo uses 5, not 3!) IDOffset = 2 // Vertical offset of ID frame above value frame TotalNodeHeight = 5 // Total rendering height MaxTextLength = 14 // Maximum length before text is truncated SliceLength = 12 // Length to slice text to when truncating )
Constants from cosmo implementation (cosmo/src/components/node.tsx)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type KeyMap ¶
type KeyMap struct {
// Navigation
Up key.Binding
Down key.Binding
Left key.Binding
Right key.Binding
// Fast navigation (with Shift modifier)
FastUp key.Binding
FastDown key.Binding
FastLeft key.Binding
FastRight key.Binding
// View controls
Center key.Binding
// Node selection
NextNode key.Binding
PrevNode key.Binding
// Actions
Search key.Binding
Menu key.Binding
Help key.Binding
Quit key.Binding
// Internal keys (for menus, search, etc.)
Enter key.Binding
Escape key.Binding
}
KeyMap defines the keybindings for the graph visualizer. All bindings are configurable to allow users to customize navigation and actions.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the default keybindings. These match the original vim-style navigation.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model represents the main bubbletea model
func NewModel ¶
func NewModel(options ...ModelOption) (Model, error)
func NewModelSimple ¶
NewModel creates a new TUI model with graph and theme. Deprecated: Use NewModel with ModelOption for better configurability.
type ModelOption ¶
ModelOption sets an option on the TUI Model. This follows the functional options pattern used in glamour and other Bubbletea components.
func WithAutoSelectFirst ¶
func WithAutoSelectFirst() ModelOption
WithAutoSelectFirst automatically selects the first node when a graph is loaded.
func WithAutoTheme ¶
func WithAutoTheme() ModelOption
WithAutoTheme automatically selects light or dark theme based on terminal settings.
func WithInitialPan ¶
func WithInitialPan(x, y int) ModelOption
WithInitialPan sets the initial viewport offset.
func WithInitialZoom ¶
func WithInitialZoom(zoom float64) ModelOption
WithInitialZoom sets the initial zoom level. Valid range: 0.5 (50%) to 2.0 (200%)
func WithKeyMap ¶
func WithKeyMap(keyMap KeyMap) ModelOption
WithKeyMap sets custom keybindings for navigation and actions.
func WithLayoutDirection ¶
func WithLayoutDirection(direction layout.Direction) ModelOption
WithLayoutDirection sets the graph layout direction. Valid directions: layout.DirectionDown, layout.DirectionUp, layout.DirectionRight, layout.DirectionLeft
func WithLayoutOptions ¶
func WithLayoutOptions(opts layout.LayoutOptions) ModelOption
WithLayoutOptions sets custom layout options for the graph.
func WithOptions ¶
func WithOptions(options ...ModelOption) ModelOption
WithOptions sets multiple Model options within a single ModelOption.
func WithSelectedNode ¶
func WithSelectedNode(nodeID string) ModelOption
WithSelectedNode sets the initially selected node.
func WithStyles ¶
func WithStyles(styles *theme.Styles) ModelOption
WithStyles sets custom lipgloss styles for rendering. This allows complete control over the visual appearance.
func WithTheme ¶
func WithTheme(themeName string) ModelOption
WithTheme sets the visual theme for the TUI. Theme names include: "aura", "dracula", "monokai", etc.
type NodePositions ¶
NodePositions stores calculated positions for each node
type SelectNodeMsg ¶
type SelectNodeMsg struct {
NodeID string
}
SelectNodeMsg represents node selection
type ShowKeybindingsMsg ¶
type ShowKeybindingsMsg struct{}
ShowKeybindingsMsg shows the keybindings help
type ThemeChangeMsg ¶
type ThemeChangeMsg struct {
ThemeName string
}
ThemeChangeMsg changes the theme