tabs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tabs is a horizontal tab bar — InkUI's "Tabs". It only manages which tab is active and renders the bar itself; actual per-tab content switching stays app-owned (the parent reads Active() and renders whichever content it has for that index), the same way picker doesn't own what "selected" means beyond reporting an index.

Example

Tabs track which one is active; the right arrow moves to the next.

package main

import (
	"fmt"

	"github.com/ows4444/tui"
	"github.com/ows4444/tui/tabs"
)

func main() {
	m := tabs.New("files", "search", "settings")
	m, _ = m.Update(tui.Key{Type: tui.KeyRight})
	fmt.Println(m.Active())
}
Output:
1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangedMsg

type ChangedMsg struct{ Index int }

ChangedMsg is delivered (via the Cmd Update returns) when the active tab changes.

type KeyMap

type KeyMap struct {
	Prev  keymap.Binding
	Next  keymap.Binding
	Cycle keymap.Binding
}

KeyMap is the set of keys Update reacts to.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default bindings: left and right move, tab cycles with wrap-around.

type Model

type Model struct {
	Labels []string
	Theme  theme.Theme

	// KeyMap holds the key bindings Update obeys. New fills it with
	// DefaultKeyMap; a Model built as a literal with no bindings set behaves
	// as if it held DefaultKeyMap.
	KeyMap KeyMap

	// Mouse, when true, makes Update handle tui.MouseEvent: a left click on
	// a tab label activates it. Off (the default) ignores the mouse.
	Mouse bool
	// Bounds is the screen rectangle where the app draws the bar (its first
	// row holds the tabs); clicks outside it are ignored.
	Bounds hittest.Rect
	// contains filtered or unexported fields
}

Model is a horizontal tab bar: Left/Right move the active tab (clamped at the ends), Tab wraps around.

func New

func New(labels ...string) Model

New builds a Model from labels, with the first tab active.

func (Model) Active

func (m Model) Active() int

Active returns the index of the currently active tab.

func (Model) Bindings

func (m Model) Bindings() []keymap.Binding

Bindings returns the active bindings, for help text.

func (Model) LayoutNode

func (m Model) LayoutNode() layout.Node

LayoutNode adapts the tab bar to a layout.Node. Measure reports its natural size (every tab " label " with one space between, one row). Render fits the allotted Size: when the bar is wider than the space, it scrolls so the active tab is always visible (its right edge if it fits, its left edge if the tab itself is wider than the space). The Model is not changed.

func (Model) Linearize

func (m Model) Linearize() string

Linearize renders the tab bar as plain text for accessible output (see tui.Linearizer): one line per tab with its label and position, and ", selected" on the active tab, e.g. "Logs, tab 2 of 3, selected". No padding or reverse-video styling. With no tabs it reads "No tabs".

func (*Model) SetActive

func (m *Model) SetActive(i int)

SetActive sets the active tab to i, clamped to a valid index (or 0 with no labels).

func (Model) SetTheme

func (m Model) SetTheme(t theme.Theme) Model

SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).

func (Model) Tokens

func (m Model) Tokens() theme.Tokens

Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentTabs, ...) and then by WithTokens.

func (Model) Update

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

Update moves the active tab on the Prev/Next bindings (clamped at the ends) or Cycle (wrapping around). With Mouse on, a left click on a tab label activates it. Any other Msg is a no-op.

func (Model) View

func (m Model) View() string

View renders the tab bar with the active tab reverse-styled.

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override. Nil fields inherit from the theme, so only the roles tok names change; the theme and every other widget are untouched. A second call replaces the first.

Jump to

Keyboard shortcuts

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