tabs

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 3 Imported by: 0

README

Tabs

Horizontal row of labeled tabs with one active label.

tabs preview

Install

glyph add tabs

This copies tabs.go (and its test file) into your repo at the path your glyph.json aliases declare. After install, the file is yours: edit it, refactor it, rename it. There is no tabs library to keep in sync.

Hello, world

package main

import (
	"fmt"

	"github.com/truffle-dev/glyph/components/tabs"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	t := tabs.New(theme.Default).
		WithTabs([]string{"chat", "logs", "diff"}).
		WithActive(0)
	fmt.Println(t.View())
}

API surface

Package: tabs

Types

  • Tabs

Functions and methods

  • New
  • WithTabs
  • WithActive
  • WithWidth
  • Update
  • View
  • Active
  • Labels

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/bubbletea@v1.3.10
  • github.com/charmbracelet/lipgloss@v1.1.0

Notes

Construct with New(theme).WithTabs([...]).WithActive(0). Forward tea.KeyMsg through Update and read Active() to switch the panel your parent model renders below the tab row.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package tabs renders a horizontal row of labeled tabs with one active label. It's a primitive: the component doesn't own the panels or their content. A parent model decides what to render below the tab row based on Active().

Keys: left/right and tab/shift+tab cycle through the labels. Cycling wraps at the ends. Update returns the new Tabs and never produces a tea.Cmd; parents can listen for changes via Active().

Index

Constants

View Source
const Separator = " · "

Separator placed between adjacent tab labels.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tabs

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

Tabs is a horizontal row of selectable labels.

func New

func New(t theme.Theme) Tabs

New constructs a Tabs primitive with the given theme. The label slice is empty until WithTabs is called.

func (Tabs) Active

func (t Tabs) Active() int

Active returns the index of the currently selected tab.

func (Tabs) Labels

func (t Tabs) Labels() []string

Labels returns a copy of the label list.

func (Tabs) Update

func (t Tabs) Update(msg tea.Msg) (Tabs, tea.Cmd)

Update handles cycling keys. Left/Right and Tab/Shift+Tab move the active index by one, wrapping at the ends. All other messages pass through.

func (Tabs) View

func (t Tabs) View() string

View renders the labeled row. The active label is bold, underlined, and uses the theme's Primary color; inactive labels use Muted.

func (Tabs) WithActive

func (t Tabs) WithActive(i int) Tabs

WithActive selects the active tab by index. Out-of-range values are clamped into the valid range; an empty label set forces 0.

func (Tabs) WithTabs

func (t Tabs) WithTabs(labels []string) Tabs

WithTabs replaces the label set. If the previous active index is out of range for the new labels, it resets to 0.

func (Tabs) WithWidth

func (t Tabs) WithWidth(w int) Tabs

WithWidth sets an optional maximum render width. Values <= 0 mean no clamp; the row renders at its natural width.

Jump to

Keyboard shortcuts

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