Documentation
¶
Overview ¶
Package tabs is a content-neutral ordered tab group and strip layout. Hosts own keys, labels, and values; this package does not know about files, issues, panes, or workspaces.
Index ¶
- Constants
- func FitEnd(text string, maxWidth int) string
- func FitEndLabel(text string, _, _, maxWidth int, _ bool) string
- func FitPath(path string, maxWidth int) string
- func FitPathLabel(text string, _, _, maxWidth int, _ bool) string
- func VisibleRange(widths []int, active, maxWidth int) (start, end int, showLeft, showRight bool)
- type CloseHover
- type CloseResult
- type FitLabel
- type Group
- func (g Group[T]) ActiveItem() (Item[T], bool)
- func (g *Group[T]) Append(key string, value T)
- func (g *Group[T]) AppendItem(item Item[T])
- func (g *Group[T]) CloseActive() CloseResult[T]
- func (g *Group[T]) CloseAt(index int) CloseResult[T]
- func (g *Group[T]) CloseMatching(pred func(Item[T]) bool) CloseResult[T]
- func (g *Group[T]) Cycle(delta int)
- func (g Group[T]) Find(key string) int
- func (g *Group[T]) OpenOrFocus(key string, value T) (index int, created bool)
- func (g *Group[T]) Select(i int)
- func (g Group[T]) VisibleRange(widths []int, maxWidth int) (start, end int, showLeft, showRight bool)
- type Hit
- type Item
- type Label
- type Strip
Constants ¶
const MaxPathLabel = 24
MaxPathLabel is the longest file-path label a tab will draw even when leftover width would let it grow. Paths past this are left-truncated so the filename stays visible.
const MinBudget = 10
MinBudget is the floor for one tab's column share, chrome and the per-tab close control included.
Variables ¶
This section is empty.
Functions ¶
func FitEndLabel ¶ added in v1.3.0
FitEndLabel is the FitLabel form of FitEnd.
func FitPath ¶ added in v1.3.0
FitPath left-truncates a file path so the filename stays visible. Cuts prefer a slash, producing labels like "…/dir/file.go". maxWidth is also clamped to MaxPathLabel so a lone tab cannot dominate the strip.
func FitPathLabel ¶ added in v1.3.0
FitPathLabel is the FitLabel form of FitPath.
func VisibleRange ¶
VisibleRange is the inclusive [start, end] window of tabs that fit in maxWidth given their rendered widths, keeping the active tab visible. showLeft and showRight are the overflow markers for tabs outside the window.
Types ¶
type CloseHover ¶ added in v1.3.0
CloseHover is the per-tab × the pointer is over. LeafID is 0 on surfaces that draw a single strip; the zero value means no × is hovered, so a surface that never sets one renders exactly as before.
func CloseHoverAt ¶ added in v1.3.0
func CloseHoverAt(leafID, index int) CloseHover
CloseHoverAt names one leaf's tab.
func (CloseHover) Index0For ¶ added in v1.3.0
func (h CloseHover) Index0For() int
Index0For is IndexFor for a surface that draws one strip and tracks no leaf.
func (CloseHover) IndexFor ¶ added in v1.3.0
func (h CloseHover) IndexFor(leafID int) int
IndexFor is the hovered tab index within leafID's strip, or -1 when the pointer is somewhere else. Hosts pass the result straight to HoverClose.
type CloseResult ¶
CloseResult tells a host what CloseMatching removed so it can clean values and decide whether to load the survivor. The group does not know about tmux, file deletion, or preview reset.
type FitLabel ¶
FitLabel shortens a tab's text so the rendered pill fits in maxWidth. maxWidth is the label column budget (chrome and close already reserved). The function returns label text, not the painted tab.
type Group ¶
Group is an ordered tab set with one active index.
func (Group[T]) ActiveItem ¶
ActiveItem is the selected tab, or false when the group is empty or Active is out of range.
func (*Group[T]) AppendItem ¶
AppendItem always adds item and selects it.
func (*Group[T]) CloseActive ¶
func (g *Group[T]) CloseActive() CloseResult[T]
CloseActive removes the selected tab. An empty group leaves Active at 0.
func (*Group[T]) CloseAt ¶
func (g *Group[T]) CloseAt(index int) CloseResult[T]
CloseAt removes the tab at index. Out of range is a no-op.
func (*Group[T]) CloseMatching ¶
func (g *Group[T]) CloseMatching(pred func(Item[T]) bool) CloseResult[T]
CloseMatching removes every item for which pred is true. Removals before the original Active are counted once, then Active is clamped.
func (*Group[T]) Cycle ¶
Cycle moves Active by delta, wrapping at the ends. Fewer than two tabs is a no-op.
func (*Group[T]) OpenOrFocus ¶
OpenOrFocus selects the first item with key, or appends value and selects it.
type Hit ¶
Hit is a drawn tab's click target. Col is relative to the strip's first column; Width is the rendered pill. CloseCol/CloseW are the × control on the pill's right edge; CloseW is 0 when the tab was too narrow to hold one.
type Strip ¶
Strip is the header row: only tabs, packed left to right.
func LayoutStrip ¶
LayoutStrip paints labels left to right with overflow markers. Leftover width goes to the active tab. Hits describe the tabs actually painted.
func (Strip) HoverClose ¶ added in v1.3.0
HoverClose repaints one tab's × as hovered. It rewrites only the cells the × already occupies, so the row keeps its width and every Hit — including the close target the pointer is inside — stays where it was registered. An index that is not painted, or a tab too narrow to carry a ×, is a no-op.
func (Strip) RegisterHits ¶ added in v1.3.0
RegisterHits calls add once for each painted tab, then once for each tab's close control. Close is registered second so it wins the cells it occupies, the same order paneframe uses for the leaf-header X.