Skip to content

Split

KeyAction
TabToggle focus between panes
Ctrl+WToggle focus between panes
Ctrl+← / Ctrl+→Resize horizontal split (±5%)
Ctrl+↑ / Ctrl+↓Resize vertical split (±5%)

Resize keys only work when SetResizable(true) is set (default: false). All other keys pass through to the focused pane.

// Horizontal: left | right
split := components.NewSplit(components.SplitHorizontal).
SetFirst(leftPane).
SetSecond(rightPane).
SetRatio(0.3) // 30% left, 70% right
// Vertical: top | bottom
split := components.NewSplit(components.SplitVertical).
SetFirst(topPane).
SetSecond(bottomPane)

SplitHorizontal is the default direction.

Split preview

Split is a two-pane container whose divider can be resized with Ctrl+Arrow when SetResizable(true). Tab or Ctrl+W toggles keyboard focus between panes.

Constructor func NewSplit() *Split

Usage

split := components.NewSplit().
SetDirection(components.SplitHorizontal).
SetFirst(tview.NewBox()).
SetSecond(tview.NewBox()).
SetRatio(0.3).
SetResizable(true).
SetShowDivider(true)
fmt.Println(split != nil)

Methods

Method Signature Description
FocusFirst func (s *Split) FocusFirst() *Split FocusFirst focuses the first pane.
FocusSecond func (s *Split) FocusSecond() *Split FocusSecond focuses the second pane.
FocusedPane func (s *Split) FocusedPane() int FocusedPane returns which pane is currently focused (0 = first, 1 = second).
GetRatio func (s *Split) GetRatio() float64 GetRatio returns the current split ratio.
SetBottom func (s *Split) SetBottom(p tview.Primitive) *Split SetBottom sets the bottom pane (vertical split).
SetDirection func (s *Split) SetDirection(dir SplitDirection) *Split SetDirection sets the split direction.
SetFirst func (s *Split) SetFirst(p tview.Primitive) *Split SetFirst sets the first pane content (left or top).
SetLeft func (s *Split) SetLeft(p tview.Primitive) *Split SetLeft sets the left pane (horizontal split).
SetMinSize func (s *Split) SetMinSize(size int) *Split SetMinSize sets the minimum pane size.
SetOnResize func (s *Split) SetOnResize(fn func(ratio float64)) *Split SetOnResize sets the callback for resize events.
SetRatio func (s *Split) SetRatio(ratio float64) *Split SetRatio sets the split ratio (0.0 to 1.0).
SetResizable func (s *Split) SetResizable(resizable bool) *Split SetResizable enables/disables resizing.
SetRight func (s *Split) SetRight(p tview.Primitive) *Split SetRight sets the right pane (horizontal split).
SetSecond func (s *Split) SetSecond(p tview.Primitive) *Split SetSecond sets the second pane content (right or bottom).
SetShowDivider func (s *Split) SetShowDivider(show bool) *Split SetShowDivider enables/disables the divider line.
SetTop func (s *Split) SetTop(p tview.Primitive) *Split SetTop sets the top pane (vertical split).
ToggleFocus func (s *Split) ToggleFocus() *Split ToggleFocus switches focus between panes.

Types

type SplitDirection SplitDirection defines the split orientation: Horizontal for a left/right arrangement, Vertical for a top/bottom arrangement.
ConstantDescription
SplitHorizontal
SplitVertical