tab

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package tab provides configuration options for the tabbed interface.

Package tab provides functionality for managing tabbed interfaces.

Package tab provides functionality for managing tabbed interfaces.

Package tab provides functionality for managing tabbed interfaces.

Package tab provides functionality for managing tabbed interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

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

Content displays the content of the active tab.

func NewContent

func NewContent(tm *Manager) *Content

NewContent creates a new Content.

func (*Content) Update

func (c *Content) Update(cont *container.Container) error

Update updates the content based on the active tab.

type EventHandler

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

EventHandler handles keyboard and mouse events for tab navigation.

func NewEventHandler

func NewEventHandler(ctx context.Context, term terminalapi.Terminal, tm *Manager, th *Header, tc *Content, cont *container.Container, cancel context.CancelFunc, opts *Options) *EventHandler

NewEventHandler initializes a new EventHandler.

func (*EventHandler) HandleKeyboard

func (eh *EventHandler) HandleKeyboard(k *terminalapi.Keyboard)

HandleKeyboard processes keyboard events for tab switching.

func (*EventHandler) HandleMouse

func (eh *EventHandler) HandleMouse(m *terminalapi.Mouse)

HandleMouse processes mouse events for tab switching.

func (*EventHandler) Refresh

func (eh *EventHandler) Refresh()

Refresh redraws the tab header and content after an external state change.

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

Header displays the tab names and highlights the active tab.

func NewHeader

func NewHeader(tm *Manager, opts *Options) (*Header, error)

NewHeader creates a new Header.

func (*Header) Advance

func (h *Header) Advance() error

Advance moves the active-tab sweep forward by one frame and redraws the header.

func (*Header) GetClickedTab

func (h *Header) GetClickedTab(p image.Point) int

GetClickedTab returns the index of the tab that was clicked based on the mouse position. Returns -1 if no tab was clicked.

func (*Header) Height

func (h *Header) Height() int

Height returns the height of the Header.

func (*Header) Update

func (h *Header) Update() error

Update refreshes the tab header to reflect changes.

func (*Header) Widget

func (h *Header) Widget() *text.Text

Widget returns the underlying text widget.

type Manager

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

Manager owns tab order, active tab state, and notification routing.

func NewManager

func NewManager(tabs ...*Tab) *Manager

NewManager returns a new Manager.

func (*Manager) AddTab

func (m *Manager) AddTab(tab *Tab)

AddTab appends one tab to the manager.

func (*Manager) GetActiveIndex

func (m *Manager) GetActiveIndex() int

GetActiveIndex returns the current active tab index.

func (*Manager) GetActiveTab

func (m *Manager) GetActiveTab() *Tab

GetActiveTab returns the current active tab.

func (*Manager) GetNotifiedIndexes

func (m *Manager) GetNotifiedIndexes() []int

GetNotifiedIndexes returns the indexes of tabs that currently have an active notification.

func (*Manager) GetNotifiedTabs

func (m *Manager) GetNotifiedTabs() []*Tab

GetNotifiedTabs returns all tabs that currently have an active notification.

func (*Manager) GetTabIndex

func (m *Manager) GetTabIndex(target *Tab) int

GetTabIndex returns the current index of target.

func (*Manager) GetTabNames

func (m *Manager) GetTabNames() []string

GetTabNames returns a copy of the current tab labels.

func (*Manager) GetTabNum

func (m *Manager) GetTabNum() int

GetTabNum returns the number of tabs currently managed.

func (*Manager) HasNotificationAt

func (m *Manager) HasNotificationAt(index int) bool

HasNotificationAt reports whether the tab at index currently has an active notification.

func (*Manager) NextTab

func (m *Manager) NextTab() bool

NextTab activates the next tab, wrapping at the end.

func (*Manager) PreviousTab

func (m *Manager) PreviousTab() bool

PreviousTab activates the previous tab, wrapping at the beginning.

func (*Manager) SetActiveTab

func (m *Manager) SetActiveTab(index int) bool

SetActiveTab makes the specified index active.

Returns true when the requested index became active.

func (*Manager) SetNotification

func (m *Manager) SetNotification(index int, active bool, duration time.Duration) bool

SetNotification replaces the notification state for the tab at index.

func (*Manager) Snapshot

func (m *Manager) Snapshot() ([]Snapshot, int)

Snapshot returns a stable copy of the header-visible manager state.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option represents a configuration option for the Tab.

func ActiveIcon

func ActiveIcon(active string) Option

ActiveIcon sets custom icons for the active state.

func ActiveTabColor

func ActiveTabColor(color cell.Color) Option

ActiveTabColor sets the background color of the active tab.

func ActiveTextColor

func ActiveTextColor(color cell.Color) Option

ActiveTextColor sets the text color of the active tab.

func AnimatedActiveTab

func AnimatedActiveTab(enable bool) Option

AnimatedActiveTab enables or disables the active-tab underline animation.

When enabled, the active tab keeps its underline while a small accent marker moves across it. Callers that prefer a calmer header can leave this disabled and still get a static underline on the active tab.

func EnableLogging deprecated

func EnableLogging(_ bool) Option

EnableLogging is a no-op kept for backward compatibility. Use LogWriter(w) to capture debug output instead.

Deprecated: use LogWriter.

func FollowNotifications

func FollowNotifications(enable bool) Option

FollowNotifications sets whether the app should follow notifications automatically.

func InactiveIcon

func InactiveIcon(inactive string) Option

InactiveIcon sets custom icons for the inactive state.

func InactiveTabColor

func InactiveTabColor(color cell.Color) Option

InactiveTabColor sets the background color of inactive tabs.

func InactiveTextColor

func InactiveTextColor(color cell.Color) Option

InactiveTextColor sets the text color of inactive tabs.

func LabelColor

func LabelColor(color cell.Color) Option

LabelColor sets the color of the tab labels.

func LogWriter

func LogWriter(w io.Writer) Option

LogWriter directs debug log output to w. Pass io.Discard (or omit the option) to silence all output. NewEventHandler never opens files.

func NotificationColor

func NotificationColor(color cell.Color) Option

NotificationColor sets the foreground color of the notification/alarm icon shown on tabs that have an active notification. Defaults to bright amber (xterm colour 214) so the icon is impossible to miss.

func NotificationIcon

func NotificationIcon(notification string) Option

NotificationIcon sets custom icons for notifications.

func SweepAccentColor

func SweepAccentColor(color cell.Color) Option

SweepAccentColor sets the accent color used by the moving underline marker.

func SweepTextColor

func SweepTextColor(color cell.Color) Option

SweepTextColor sets the text color used while the active sweep passes.

func Tabs

func Tabs(tabs ...*Tab) Option

Tabs sets the root tabs of the Tab widget.

type Options

type Options struct {
	Tabs                []*Tab     // List of tabs.
	LabelColor          cell.Color // Color of the tab labels.
	ActiveTextColor     cell.Color // Text color of the active tab.
	InactiveTextColor   cell.Color // Text color of inactive tabs.
	ActiveTabColor      cell.Color // Background color of the active tab.
	InactiveTabColor    cell.Color // Background color of inactive tabs.
	ActiveIcon          string     // Icon for active tabs.
	InactiveIcon        string     // Icon for inactive tabs.
	NotificationIcon    string     // Icon for tabs with notifications.
	NotificationColor   cell.Color // Foreground color of the notification icon (alarm indicator).
	AnimatedActiveTab   bool       // Enables a moving accent marker in the active tab underline row.
	SweepTextColor      cell.Color // Text color used under the active sweep.
	SweepAccentColor    cell.Color // Accent color used for the moving underline marker.
	LogWriter           io.Writer  // Destination for debug logs; nil disables logging.
	FollowNotifications bool       // Whether to follow notifications automatically.
}

Options holds the configuration for the Tab.

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions initializes default options or applies provided options.

type Snapshot

type Snapshot struct {
	Name         string
	Notification bool
}

Snapshot captures the header-visible state of a tab.

type Tab

type Tab struct {
	// Name is the label shown in the tab header.
	Name string
	// Content is the container option used to render the tab body.
	Content container.Option
	// contains filtered or unexported fields
}

Tab stores one tab label and the container content shown when the tab is active.

The notification state is protected separately so callers can cheaply ask a tab whether it still has an active notification without holding the manager lock.

func (*Tab) HasNotification

func (t *Tab) HasNotification() bool

HasNotification reports whether the tab currently has an active notification.

Expired notifications are cleared lazily when observed so callers do not need a dedicated sweeper.

Directories

Path Synopsis
Binary tabdemo shows the tab widget in a unified multi-widget dashboard.
Binary tabdemo shows the tab widget in a unified multi-widget dashboard.

Jump to

Keyboard shortcuts

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