splitpane

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackMsg

type BackMsg struct{}

BackMsg is sent when navigating back (Esc at root level)

type Config

type Config struct {
	// Required
	Styles          *styles.Styles
	DetailsRenderer DetailsRenderer

	// Optional: title shown in the left pane header (default: none)
	Title string

	// Optional with defaults
	LeftPaneRatio  float64        // Default: 0.4
	MaxExpandDepth int            // Default: 2
	SectionGrouper SectionGrouper // Default: no sections
	HeaderRenderer HeaderRenderer // Default: standard header with title and breadcrumb
	FooterRenderer FooterRenderer // Default: standard keyboard hints

	// Section names (if using default grouper)
	// e.g., {"resource": "Resources"}
	SectionNames map[string]string
}

Config configures the split-pane model.

type DetailsRenderer

type DetailsRenderer interface {
	RenderDetails(item Item, width int, styles *styles.Styles) string
}

DetailsRenderer renders the right pane content for a selected item. Consumers implement this for domain-specific detail views.

type DrillDownMsg

type DrillDownMsg struct {
	Item Item
}

DrillDownMsg is sent when drilling into an item

type FooterRenderer

type FooterRenderer interface {
	RenderFooter(model *Model, styles *styles.Styles) string
}

FooterRenderer renders custom footer content. Optional - if nil, uses default keyboard hints footer.

type HeaderRenderer

type HeaderRenderer interface {
	RenderHeader(model *Model, styles *styles.Styles) string
}

HeaderRenderer customizes the left pane header. Optional - if nil, uses default header with title and breadcrumb.

type Item

type Item interface {
	// GetID provides a unique identifier that is primarily
	// used for expansion tracking in the split pane
	GetID() string
	// GetName provides a human-readable name for the item
	GetName() string
	// GetIcon provides a status icon (styled when not selected)
	GetIcon(selected bool) string
	// GetAction provides action badge text (e.g "CREATE", "UPDATE", etc.)
	GetAction() string
	// GetDepth provides the nesting depth for indentation
	GetDepth() int
	// GetParentID returns the parent item ID (empty for top-level items)
	GetParentID() string
	// GetItemType returns the type for section grouping (e.g., "resource", "child")
	GetItemType() string
	// IsExpandable indicates whether the item can be expanded in-place
	IsExpandable() bool
	// CanDrillDown indicates whether the item can be drilled into for detailed view
	CanDrillDown() bool
	// GetChildren provides a list of child items
	// displayed when the current item is expanded
	GetChildren() []Item
}

Item represents a selectable item in the left pane. Consumers implement this interface for their domain-specific items.

type ItemExpandedMsg

type ItemExpandedMsg struct {
	Item     Item
	Expanded bool
}

ItemExpandedMsg is sent when an item is expanded/collapsed

type ItemSelectedMsg

type ItemSelectedMsg struct {
	Item Item
}

ItemSelectedMsg is sent when the selected item changes

type ItemsUpdatedMsg

type ItemsUpdatedMsg struct{}

ItemsUpdatedMsg can be sent to trigger a viewport refresh when items have been modified externally

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is a Bubble Tea model for a two-pane split view. Left pane shows a navigable list; right pane shows details.

func New

func New(config Config) Model

New creates a new split-pane model with the given configuration.

func (*Model) AddItem

func (m *Model) AddItem(item Item)

AddItem adds an item to the end of the root items list. If currently in drill-down, the item is added to root but the view refreshes appropriately.

func (Model) Config

func (m Model) Config() Config

Config returns the configuration.

func (Model) FocusedPane

func (m Model) FocusedPane() PaneType

FocusedPane returns which pane currently has focus.

func (Model) Height

func (m Model) Height() int

Height returns the total height.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model

func (Model) IsExpanded

func (m Model) IsExpanded(id string) bool

IsExpanded returns true if the item with the given ID is expanded.

func (Model) IsInDrillDown

func (m Model) IsInDrillDown() bool

IsInDrillDown returns true if currently viewing a drilled-down item.

func (Model) Items

func (m Model) Items() []Item

Items returns the current items at the current navigation level.

func (Model) LeftPaneWidth

func (m Model) LeftPaneWidth() int

LeftPaneWidth returns the left pane width.

func (Model) NavigationPath

func (m Model) NavigationPath() []string

NavigationPath returns the breadcrumb path as a slice of names.

func (Model) NavigationStack

func (m Model) NavigationStack() []NavigationFrame

NavigationStack returns the navigation stack for drill-down.

func (*Model) RefreshViewports added in v0.1.3

func (m *Model) RefreshViewports()

RefreshViewports forces a re-render of both viewport contents. Use this when item data has changed but items themselves haven't been replaced, or when you need to ensure the displayed content is up-to-date.

func (*Model) RemoveItemByID

func (m *Model) RemoveItemByID(id string) bool

RemoveItemByID removes an item by ID from root items. Returns true if the item was found and removed.

func (Model) RightPaneWidth

func (m Model) RightPaneWidth() int

RightPaneWidth returns the right pane width.

func (Model) RootItems

func (m Model) RootItems() []Item

RootItems returns the root-level items.

func (Model) SelectedID

func (m Model) SelectedID() string

SelectedID returns the ID of the currently selected item.

func (Model) SelectedIndex

func (m Model) SelectedIndex() int

SelectedIndex returns the currently selected index.

func (Model) SelectedItem

func (m Model) SelectedItem() Item

SelectedItem returns the currently selected item, or nil if none. Uses ID-based lookup to ensure the correct item is returned even after updates.

func (*Model) SetItems

func (m *Model) SetItems(items []Item)

SetItems sets the items to display, resetting all state. Use UpdateItems() instead if you want to preserve selection and expansion state.

func (Model) Styles

func (m Model) Styles() *styles.Styles

Styles returns the configured styles.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update implements tea.Model

func (*Model) UpdateItemByID

func (m *Model) UpdateItemByID(id string, newItem Item) bool

UpdateItemByID replaces an item by ID in both root and current items. Returns true if the item was found and updated.

func (*Model) UpdateItems

func (m *Model) UpdateItems(items []Item)

UpdateItems replaces items while preserving user state where possible. - Preserves selection if the selected item still exists (by ID) - Preserves expansion state for items that still exist - Properly handles drill-down mode by refreshing children from updated parent

func (Model) View

func (m Model) View() string

View implements tea.Model

func (Model) Width

func (m Model) Width() int

Width returns the total width.

type NavigationFrame struct {
	// ParentID is the identifier of the item drilled into
	ParentID string
	// ParentName is the display name for the breadcrumb
	ParentName string
	// SelectedID is the ID of the item that was selected before drilling down
	SelectedID string
	// Items are the items at this level (snapshot for back navigation)
	Items []Item
}

NavigationFrame represents a frame in the drill-down navigation stack

type PaneType

type PaneType int

PaneType indicates which pane is focused

const (
	LeftPane PaneType = iota
	RightPane
)

type QuitMsg

type QuitMsg struct{}

QuitMsg is sent when the user presses q/ctrl+c

type Section

type Section struct {
	Name  string
	Items []Item
}

Section groups items under a header in the left pane

type SectionGrouper

type SectionGrouper interface {
	GroupItems(items []Item, isExpanded func(id string) bool) []Section
}

SectionGrouper organizes items into named sections. Optional - if nil, items render without section headers.

Jump to

Keyboard shortcuts

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