workspacelist

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 11 Imported by: 0 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 workspacelist is the presentation component shared by the project Workspaces sidebar and the global Workspaces browser.

It owns the parts of a workspace list that both consumers must agree on — stable-ID selection, the filter input and its pure multi-field matcher, sort modes and their stable ordering, activity grouping, the viewport and its scrollbar, and the empty/no-match rows. It owns none of the parts that belong to a data owner: it cannot inspect tmux, read Git, switch projects, create worktrees, or attach to a terminal. Callers project their own records into Item and hand back a row renderer for source-specific metadata.

The rule that keeps this honest: nothing in this package imports a plugin, the app, or the inventory. It receives resolved display fields only.

Both consumers render through RenderSidebar. Global Model supplies sort sections and a sort action; project Workspaces supplies Shells/Workspaces sections and optional creation actions. The component lays out both without learning what those actions do.

Index

Constants

View Source
const (
	RecentNew      = "New"
	RecentToday    = "Today"
	RecentThisWeek = "This week"
	RecentOlder    = "Older"
)

Recent time-bucket headings. Empty buckets are omitted.

View Source
const (
	KindWorktree = "worktree"
	KindShell    = "shell"
)

Kind is a presentation identity for a row. These strings match the catalog kinds the caller already resolved; this package never imports inventory.

View Source
const PulseInterval = 175 * time.Millisecond

PulseInterval is the frame period every surface that breathes a working or blocked marker advances on. Sharing it keeps the project sidebar and the global Workspaces list visually in step rather than beating against each other at different rates.

View Source
const SortGlyph = "⇅"

SortGlyph marks the header control as a sort rather than a caption. A bare "Activity" in the corner of a panel says nothing about why it is there; the same word behind ⇅ says the list is ordered by it and that the control is worth pressing.

It is ⇅ rather than the word "Sort:" because the control shares its row with the create button and, on a narrow sidebar, six columns of label is the difference between both controls fitting and neither. It is ⇅ rather than a single arrow because the list offers no direction to point in — a ↓ would be answering a question nobody asked. U+21C5 is ordinary Unicode, not a Nerd Font glyph, so it survives a plain terminal font.

Variables

View Source
var (
	WorkingPulse = []float64{1.00, 0.96, 0.87, 0.75, 0.62, 0.50, 0.42, 0.38, 0.42, 0.50, 0.62, 0.75, 0.87, 0.96}
	BlockedPulse = []float64{1.00, 0.78, 0.52, 0.88, 1.00, 0.68, 0.43, 0.38, 0.38, 0.38, 0.38, 0.38, 0.43, 0.52, 0.68, 0.84}
)

Working breathes evenly. Blocked uses two brighter beats followed by a longer rest so it attracts attention without making the whole row blink.

SortModes is the cycle order behind the global list's sort control. Manual is absent: it means something only to a consumer that owns its input order.

Functions

func ApplySelection

func ApplySelection(content string, width int, selected, focused bool) string

ApplySelection gives both consumers the same focused and unfocused cursor treatment while leaving their row text and icons caller-owned. Do not wrap a pre-rendered marker: lipgloss.Render resets all attributes, and the name after the icon will lose the fill. Use RenderRow, which paints the marker and the name as sibling spans.

func BlendColor added in v1.0.0

func BlendColor(low, high color.Color, amount float64) color.Color

func KindGlyph

func KindGlyph(kind string) string

KindGlyph is the Agents-board pair: worktree ⑂, shell ❯. Unknown or empty kinds render nothing so a project-plugin row can omit them.

func Match

func Match(item Item, query string) bool

Match reports whether an item satisfies a query. Matching is case-insensitive and space-separated: every token must appear somewhere in the item's promised fields, so "sidecar modal" narrows rather than widens. An empty or whitespace-only query matches everything.

func MatchFields

func MatchFields(query string, fields ...string) bool

MatchFields is the same matcher for callers that have not built an Item — the project sidebar filters its own worktree and shell records this way, so both consumers share one definition of "matches".

func MoveIndex

func MoveIndex(index, delta, count int) int

MoveIndex applies the shared clamped selection semantics used by keyboard and wheel navigation in both workspace sidebars.

func NoMatchRow

func NoMatchRow(width int, query string) string

NoMatchRow is the honest empty state for a query that matches nothing. A blank list would read as "nothing exists" rather than "nothing matches".

func PulseCircle added in v1.0.0

func PulseCircle(level float64) string

func PulseDiamond added in v1.0.0

func PulseDiamond(level float64) string

func PulseLane added in v1.0.0

func PulseLane(lane string) bool

PulseLane reports whether a lane is one of the two live states that breathe.

func PulseLevel added in v1.0.0

func PulseLevel(levels []float64, frame int) float64

func PulseMarker added in v1.0.0

func PulseMarker(lane string, frame int) (icon string, style lipgloss.Style, ok bool)

PulseMarker is the animated form of a working or blocked marker at a given frame. ok is false for every other lane, so callers can fall back to the static marker they already resolved.

func PulseStyle added in v1.0.0

func PulseStyle(base color.Color, level float64, bold bool) lipgloss.Style

func RelativeAge

func RelativeAge(changedAt, now time.Time) string

RelativeAge formats freshness in the same small units the Agents board uses, so one item does not read "3m" on one tab and "3 minutes" on the other.

Everything under a minute reads "now". A second-level countdown is a claim to precision this data cannot back: last-interaction time is inferred from tmux and session files and is routinely off by more than the digits it is showing. It also churned — every row that had just moved redrew its number once a second, so the weakest number on the surface was also the one drawing the eye. "now" is the honest form of the same fact and it holds still.

func RenderRow

func RenderRow(row RowPresentation, width int, selected, focused bool) []string

RenderRow renders one or two physical lines. Line one carries the row's whole identity — kind glyph, project, name, and its age — so a reader can scan shells and worktrees apart without dropping to the second line. Line two is agent detail alone and collapses to nothing when there is none. Narrow rows retain the status marker and name first, then add secondary identity only while space remains.

func ResizePercent

func ResizePercent(start, deltaColumns, viewportWidth int) int

ResizePercent applies the shared percentage delta and bounds used by both workspace dividers.

func SectionTitle

func SectionTitle(name string, count int) string

SectionTitle words a list section's heading. Both the project sidebar and the global browser render through it so a heading cannot gain a count on one surface and lose it on the other.

The Kanban board words its lane headers itself: a column is as narrow as 17 columns there, which "Needs Attention (0)" overruns, and its label and count carry different colours rather than one string.

func SortActionID added in v1.0.0

func SortActionID(mode Sort) string

SortActionID names the choice a View surface reports when a sort is picked. Both surfaces build their own sections — they offer different modes and different extra toggles — but they must not invent two names for the same choice, or a shared handler would answer to one and ignore the other.

func SortIndex added in v1.0.0

func SortIndex(mode Sort, modes []Sort) int

SortIndex is a mode's position in the offered set, for a list cursor.

func SortPillLabel added in v1.0.0

func SortPillLabel(mode Sort) string

SortPillLabel is what the header control reads.

Types

type Filter

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

Filter is the inline `/` query and its focus state. It is deliberately a plain value: filter state is in-memory per consumer and is never written to config or project state.

func (*Filter) Active

func (f *Filter) Active() bool

Active reports that the filter still affects the list. A query survives losing focus so a user can filter, press enter, and keep working inside the narrowed list.

func (*Filter) Blur

func (f *Filter) Blur()

Blur releases focus without discarding the query.

func (*Filter) Focus

func (f *Filter) Focus()

Focus enters filtering. `/` is the explicit entry precisely so printable project commands (n, D, p) keep working when it is not focused.

func (*Filter) Focused

func (f *Filter) Focused() bool

func (*Filter) HandleKey

func (f *Filter) HandleKey(key, text string) KeyResult

HandleKey applies one key while the filter has focus. It returns KeyIgnored for anything the list should handle itself.

func (*Filter) Insert

func (f *Filter) Insert(text string)

Insert appends typed or pasted text. Pastes go through the same path as keystrokes so a pasted branch name filters exactly like a typed one.

func (*Filter) Query

func (f *Filter) Query() string

func (*Filter) RenderRow

func (f *Filter) RenderRow(width, matched, total int) string

RenderRow draws the one-line filter affordance both consumers show. It is shared so the project sidebar and the global browser cannot drift on what filtering looks like or on how counts are phrased.

func (*Filter) Reset

func (f *Filter) Reset()

Reset clears both query and focus — used when the underlying list is replaced wholesale (a project switch, a plugin reinit).

func (*Filter) SetQuery

func (f *Filter) SetQuery(query string)

type Group

type Group string

Group is an item's presentation bucket. The buckets are a vertical projection of the shared Kanban semantics — they are assigned by the caller from resolved agentstatus, not derived here, so this package never becomes a second status reducer.

const (
	GroupNeedsAttention Group = "Needs Attention"
	GroupWorking        Group = "Working"
	GroupDone           Group = "Done"
	GroupLive           Group = "Live"
	GroupIdle           Group = "Idle"
	GroupPaused         Group = "Paused"
	GroupNoSession      Group = "No Session"
)

func GroupForLane added in v1.0.0

func GroupForLane(lane string) Group

GroupForLane is the vertical projection of a resolved agent lane, shared by every consumer that groups by activity.

It takes the lane as a string rather than an agentstatus.LaneID so this package keeps its promise not to import a status reducer: it does not decide what "blocked" means, only where a row already resolved as blocked belongs in a list. An unrecognised lane lands in Paused, which is the bucket for "something is here and its state is not legible" — a row this does not recognise is still a row someone has to see.

func Groups

func Groups() []Group

Groups returns the activity group order. Callers render headings in this order so a group that gains its first item never appears in a new place.

type Item

type Item struct {
	ID           string
	Name         string
	NameMeta     []RowField
	Project      string
	ProjectKey   string
	ProjectOrder int
	Branch       string
	Task         string
	Provider     string
	// TmuxName is an identity key, never rendered. It is searchable so two
	// shells sharing a display name inside one project can be told apart.
	TmuxName string
	Status   string
	Detail   string
	// Kind is a presentation string ("worktree" / "shell"), not a catalog type.
	Kind      string
	Marker    RowMarker
	Group     Group
	ChangedAt time.Time
	Data      any
}

Item is one row's resolved display identity. Every field is presentation input: the component matches, sorts, groups, and renders from these values and reads nothing behind them. Data carries the caller's own record so a selection can be resolved back to its owner without this package knowing the type.

func Filtered

func Filtered(items []Item, query string) []Item

Filtered returns the items matching query, preserving input order.

func Sorted

func Sorted(items []Item, mode Sort) []Item

Sorted orders items for presentation. Every mode is stable: equal keys keep the caller's order, so an unchanged poll cannot churn the list.

type KeyResult

type KeyResult uint8

KeyResult tells a consumer what a key did to the filter, so the list keeps its own navigation while the filter owns the text.

const (
	// KeyIgnored: the filter did not want this key. Navigation keys land here
	// on purpose — arrows and ctrl+n/ctrl+p must stay live while filtering.
	KeyIgnored KeyResult = iota
	// KeyHandled: the query changed (or a first escape cleared it).
	KeyHandled
	// KeyAccept: enter — leave the focused item selected, return to the list.
	KeyAccept
	// KeyExit: escape on an empty query — filter focus is released.
	KeyExit
)

type MarkerTone

type MarkerTone string

MarkerTone describes non-semantic row identities and health states. Agent activity should use Lane instead; the caller has already resolved that lane and this renderer only gives the resolved marker its shared visual treatment.

const (
	MarkerMuted   MarkerTone = "muted"
	MarkerLive    MarkerTone = "live"
	MarkerMain    MarkerTone = "main"
	MarkerWarning MarkerTone = "warning"
	MarkerError   MarkerTone = "error"
)

type Model

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

Model is the list state a consumer owns: the catalog projection, the chosen sort, the filter, and the selection/viewport. Selection is by stable ID, so a refresh, a filter keystroke, or a sort change moves the cursor with the item rather than with the row number.

func (*Model) Bottom

func (m *Model) Bottom() bool

func (*Model) Counts

func (m *Model) Counts() (matched, total int)

func (*Model) CycleSort

func (m *Model) CycleSort()

CycleSort advances `s` through Activity → Project → Recent → Name.

func (*Model) Filter

func (m *Model) Filter() *Filter

func (*Model) FilterKey

func (m *Model) FilterKey(key, text string) KeyResult

FilterKey applies a key while the filter owns focus and reprojects when the query changed.

func (*Model) FocusFilter

func (m *Model) FocusFilter()

FocusFilter is the `/` entry point.

func (*Model) IsPinned

func (m *Model) IsPinned(id string) bool

IsPinned reports whether id is in the pin list.

func (*Model) Items

func (m *Model) Items() []Item

func (*Model) Move

func (m *Model) Move(delta int) bool

Move steps the selection, clamping at both ends rather than wrapping.

func (*Model) NeedsPulse added in v1.0.0

func (m *Model) NeedsPulse() bool

NeedsPulse reports whether any currently visible row carries a lane that breathes, so a consumer can keep its animation clock off when nothing on screen would move.

func (*Model) PinnedIDs

func (m *Model) PinnedIDs() []string

PinnedIDs returns the configured pin order, including IDs that are not currently visible.

func (*Model) Render

func (m *Model) Render(opts RenderOptions) Rendered

Render draws the list: header with the active sort, filter row, section headings, rows, and a scrollbar. Headings scroll with their rows so the heading a row sits under is always the heading above it.

func (*Model) Reproject

func (m *Model) Reproject()

Reproject re-runs filter and sort after a caller changed the query directly (a paste, a programmatic clear). Selection is preserved by identity.

func (*Model) Scroll

func (m *Model) Scroll(delta int)

Scroll follows the selected row. It remains as the compatibility entry point for callers that previously moved only the viewport; workspace wheel input must have the same selection-following semantics everywhere.

func (*Model) ScrollAtBoundary added in v1.0.0

func (m *Model) ScrollAtBoundary(delta int) bool

ScrollAtBoundary reports whether moving the selection by delta would leave this list unchanged. Wheel navigation follows selection, so its boundary is the first or last visible item rather than the viewport offset alone.

func (*Model) ScrollOffset

func (m *Model) ScrollOffset() int

ScrollOffset is the first visible row index. Consumers read it to prove the viewport survived a refresh; nothing else depends on it.

func (*Model) SelectID

func (m *Model) SelectID(id string) bool

SelectID moves the cursor to a stable identity when it is visible.

func (*Model) Selected

func (m *Model) Selected() (Item, bool)

func (*Model) SelectedID

func (m *Model) SelectedID() string

func (*Model) SetCreateActions added in v1.0.0

func (m *Model) SetCreateActions(header *SidebarAction, sections map[string]*SidebarAction)

SetCreateActions supplies presentation-only create affordances. Section actions are keyed by Section.Key, which is a stable project identity under Project sort. Nil removes the corresponding affordance and hit region.

func (*Model) SetEmptyText

func (m *Model) SetEmptyText(text string)

func (*Model) SetFailures

func (m *Model) SetFailures(failures []string)

SetFailures records per-project unavailability rows. They are presentation only; the list never retries or repairs anything.

func (*Model) SetItems

func (m *Model) SetItems(items []Item)

SetItems replaces the catalog projection, preserving the selected identity.

func (*Model) SetLoading

func (m *Model) SetLoading(loading bool)

SetLoading marks that inventory is still arriving. Rows already collected stay on screen: incremental results are the point.

func (*Model) SetPinned

func (m *Model) SetPinned(ids []string)

SetPinned replaces the pin order. IDs that are not in the current catalog are kept until the next reproject so a later SetItems can restore them; display only includes pins that still have a matching item.

func (*Model) SetPulseFrame added in v1.0.0

func (m *Model) SetPulseFrame(frame int)

SetPulseFrame advances the working/blocked marker animation. Consumers that never tick leave it at zero and get the steady first frame.

func (*Model) SetSort

func (m *Model) SetSort(mode Sort)

func (*Model) Sort

func (m *Model) Sort() Sort

func (*Model) TogglePin

func (m *Model) TogglePin(id string) []string

TogglePin pins or unpins id and returns the new pin order. First-pinned first: a new pin is appended.

func (*Model) Top

func (m *Model) Top() bool

func (*Model) Visible

func (m *Model) Visible() []Item

type Region

type Region struct {
	Kind          RegionKind
	ID            string
	X, Y, W, H    int
	VisibleIndex  int
	SectionHeader bool
	Data          any
}

func RegionAt

func RegionAt(regions []Region, x, y int) (Region, bool)

RegionAt resolves a click to the region drawn under it, last registered winning — the same rule the workspace plugin's hit map uses.

type RegionKind

type RegionKind string

RegionKind names a mouse target the list drew. Regions are reported from the same layout that rendered the rows, so a hit test can never disagree with what is on screen.

const (
	RegionRow    RegionKind = "workspacelist-row"
	RegionSort   RegionKind = "workspacelist-sort"
	RegionFilter RegionKind = "workspacelist-filter"
)
const (
	RegionHeaderAction  RegionKind = "workspacelist-header-action"
	RegionSectionAction RegionKind = "workspacelist-section-action"
	RegionEmptyAction   RegionKind = "workspacelist-empty-action"
)

type RenderOptions

type RenderOptions struct {
	Width, Height int
	Title         string
	Focused       bool
	Now           time.Time
}

RenderOptions describes the box the list is drawn into.

type Rendered

type Rendered struct {
	View    string
	Regions []Region
}

Rendered is the drawn list plus the regions it registered.

type RowField

type RowField struct {
	Text     string
	Rendered string
}

RowField carries both the semantic text used under selection and an optional styled form used on an unselected row. This lets project-only badges remain project-owned without moving their layout into the plugin.

func PlainField

func PlainField(text string) RowField

type RowMarker

type RowMarker struct {
	Icon     string
	Lane     string
	Tone     MarkerTone
	Style    lipgloss.Style
	HasStyle bool
}

RowMarker is a caller-resolved status symbol. Style is reserved for the project sidebar's animated working/blocked frames; ordinary callers provide Lane or Tone and get the same colour vocabulary everywhere.

type RowPresentation

type RowPresentation struct {
	Marker     RowMarker
	Kind       string
	Name       string
	NamePrefix RowField
	Age        string
	NameMeta   []RowField

	BeforeProvider []RowField
	Provider       string
	AfterProvider  []RowField
	Pinned         bool
}

RowPresentation is the neutral two-line workspace row contract shared by the project and global Workspaces surfaces. Callers resolve all state and supply display fields; this package owns layout, marker placement, provider treatment, ANSI-safe fitting, and selection.

Kind is a presentation field, not a status marker. Marker stays the outdented gutter icon (working/live/idle/ambiguous/main).

type Section

type Section struct {
	Title string
	// Key is the stable grouping identity when a section represents a project.
	// Presentation callers can hang an action from it without decoding Title.
	Key   string
	Group Group
	Items []Item
}

Section is a rendered group of items with its heading. Title is the heading without a count; empty Title means an unheaded run. Group is the Activity bucket when that sort is in play.

func Grouped

func Grouped(items []Item, mode Sort) []Section

Grouped splits sorted items into headed sections. Activity uses the Kanban projection; Project one heading per project; Recent the time buckets; Name stays a single unheaded run.

func GroupedAt

func GroupedAt(items []Item, mode Sort, now time.Time, pinnedIDs []string) []Section

GroupedAt is Grouped with a clock for Recent buckets and an optional pinned identity list. Pinned items that still exist sit in a headed "Pinned" section first and are not re-bucketed below. Gone pin IDs are dropped.

type SidebarAction

type SidebarAction struct {
	ID      string
	Label   string
	Hovered bool
}

SidebarAction is an optional action painted in a header. Omitting it paints and registers nothing, which lets read-only consumers use the same sidebar without inheriting project workspace mutations.

type SidebarOptions

type SidebarOptions struct {
	Width, Height int
	Title         string
	Focused       bool
	SelectedID    string
	ScrollOffset  int
	HeaderAction  *SidebarAction
	HeaderMeta    *SidebarAction
	PrefixLines   []string
	FilterLine    string
	FilterActive  bool
	Sections      []SidebarSection
	EmptyLines    []string
	// EmptyActionID names one of EmptyLines as a pressable control and gives
	// it a hit region. An empty state that offers an action has to be
	// clickable for the same reason its key has to be advertised: the two
	// interaction models say the same thing or neither is trustworthy.
	EmptyActionID   string
	EmptyActionLine int
	FooterLines     []string
}

SidebarOptions contains only resolved presentation state. Collection, selection side effects, preview loading and mutations stay with the caller.

type SidebarRendered

type SidebarRendered struct {
	View         string
	Regions      []Region
	ScrollOffset int
	VisibleRows  int
}

SidebarRendered is the exact view, geometry and viewport produced by one layout pass. Regions use content-local coordinates; callers add their panel border/padding origin once when registering them.

func RenderSidebar

func RenderSidebar(opts SidebarOptions) SidebarRendered

RenderSidebar is the single row/section/viewport/scrollbar/hit-region renderer used by project and global Workspaces.

type SidebarRow

type SidebarRow struct {
	ID     string
	Data   any
	Render func(width int, selected, focused bool) []string
}

SidebarRow is one caller-owned record projected into the shared list. Data is returned unchanged in the row's Region so consumers never decode display text or a volatile visible index to recover their record.

type SidebarSection

type SidebarSection struct {
	Title  string
	Count  int
	Action *SidebarAction
	Rows   []SidebarRow
}

SidebarSection is a headed run of rows. The optional action is commonly the project's create-shell/create-worktree affordance; global sections omit it.

Title is the bare name ("Shells", "Needs Attention") and Count is rendered beside it. They are kept apart rather than pre-joined so a narrow heading can drop the count and still name its rows. An empty Title means an unheaded run.

type Sort

type Sort uint8

Sort is an explicit user-chosen ordering. Sorting is presentation only: it never changes identities, and it never triggers collection.

const (
	SortActivity Sort = iota
	SortProject
	SortRecent
	SortName
	// SortManual is the caller's own order, left exactly as handed in. It is
	// offered only where a durable order actually exists — the project
	// sidebar's fixed Shells/Worktrees structure, and later its drag order.
	// Global inventory does not pretend to own Git or tmux ordering, so it
	// does not offer this.
	SortManual
)

func SortFromAction added in v1.0.0

func SortFromAction(action string, modes []Sort) (Sort, bool)

SortFromAction resolves an action ID back to a mode within the offered set.

func SortFromLabel added in v1.0.0

func SortFromLabel(label string, modes []Sort) (Sort, bool)

SortFromLabel resolves a persisted label back to a mode within the offered set, case-insensitively. Labels are what surfaces persist: they read plainly in a state file and survive the enum being reordered. A label this set does not offer reports false so the caller can fall back to its own default rather than land on an arbitrary mode.

func (Sort) Label

func (s Sort) Label() string

func (Sort) Next

func (s Sort) Next() Sort

Next cycles to the following sort mode.

Jump to

Keyboard shortcuts

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