Skip to content

Tabs

KeyAction
TabNext tab
Shift+TabPrevious tab
HPrevious tab
LNext tab
19Jump directly to tab by position
xClose current tab (requires SetClosable(true))
tabs := components.NewTabs()
tabs.AddTab("Overview", overviewView)
tabs.AddTab("Logs", logView)
tabs.AddTab("Settings", settingsView)

SetActive(index) switches programmatically. OnChange fires whenever the active tab changes.

SetClosable(true) enables the x key to close the active tab and fires OnClose with the tab index. The component does not remove the tab automatically — remove it in the OnClose handler so you control cleanup.

Tabs preview

Tabs is a tabbed container. Tab/Shift+Tab and H/L cycle tabs; 1–9 jump directly; x closes the active tab when SetClosable(true) is set.

Constructor func NewTabs() *Tabs

Usage

tabs := components.NewTabs().
AddTab("Overview", tview.NewBox()).
AddTabWithIcon("Logs", "", tview.NewBox()).
AddTab("Settings", tview.NewBox()).
SetShowIcons(true).
SetClosable(true)
tabs.SetBadge("Logs", 3)
tabs.SetActiveByName("Logs")
fmt.Println(tabs != nil)

Methods

Method Signature Description
AddTab func (t *Tabs) AddTab(name string, content tview.Primitive) *Tabs AddTab adds a new tab.
AddTabWithIcon func (t *Tabs) AddTabWithIcon(name, icon string, content tview.Primitive) *Tabs AddTabWithIcon adds a new tab with an icon.
ClearBadge func (t *Tabs) ClearBadge(name string) *Tabs ClearBadge clears the badge on a tab.
GetActive func (t *Tabs) GetActive() int GetActive returns the active tab index.
GetActiveTab func (t *Tabs) GetActiveTab() *Tab GetActiveTab returns the active tab.
RemoveTab func (t *Tabs) RemoveTab(index int) *Tabs RemoveTab removes a tab by index.
SetActive func (t *Tabs) SetActive(index int) *Tabs SetActive sets the active tab by index.
SetActiveByName func (t *Tabs) SetActiveByName(name string) *Tabs SetActiveByName sets the active tab by name.
SetBadge func (t *Tabs) SetBadge(name string, count int) *Tabs SetBadge sets a badge count on a tab.
SetClosable func (t *Tabs) SetClosable(closable bool) *Tabs SetClosable enables/disables tab closing.
SetOnChange func (t *Tabs) SetOnChange(fn func(index int, name string)) *Tabs SetOnChange sets the callback for tab changes.
SetOnClose func (t *Tabs) SetOnClose(fn func(index int) bool) *Tabs SetOnClose sets the callback for tab close requests. Return false to prevent closing.
SetShowBadges func (t *Tabs) SetShowBadges(show bool) *Tabs SetShowBadges enables/disables badge display.
SetShowIcons func (t *Tabs) SetShowIcons(show bool) *Tabs SetShowIcons enables/disables icon display.
TabCount func (t *Tabs) TabCount() int TabCount returns the number of tabs.

Types

type Tab struct Tab holds the display metadata and content primitive for a single tab. Badge renders a numeric count badge on the tab header when > 0.
FieldTypeDescription
Name string
Icon string
Badge int
Content tview.Primitive