projectlist

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 3 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 projectlist is the state-free presentation core behind Sidecar's project collection: what a destination looks like, how the collection is filtered and ordered, and how its metadata reads.

It holds no Bubble Tea state and touches no filesystem, so a headless caller can adopt the same filtering, ordering and formatting the modal uses. The modal sections above it decide only where things are drawn and which regions are clickable. It deliberately mirrors internal/workspacelist's vocabulary — Label, SortActionID, SortFromLabel, SortIndex — because the two collection surfaces answer the same question and must not invent two names for it.

Index

Constants

View Source
const (
	// CardWidth is the card's total width including its border.
	CardWidth = 32
	// CardGap is the space between columns. One column rather than two: three
	// cards, two gaps and the scrollbar's column have to fit the modal's
	// content width together, and a second column of gap is what costs the
	// third card.
	CardGap = 1
	// CardHeight is the card's total height including its border. Six rows is
	// what holds a name row, a path row, breathing space and a metadata row.
	CardHeight = 6
	// MaxGridColumns caps the grid. A fourth column is reachable on a very
	// wide terminal but the modal is not that wide, and a collection that
	// reflows between three and four columns as the window moves is harder to
	// re-find a project in than one that does not.
	MaxGridColumns = 3
)

Grid geometry. The card is a fixed shape rather than a share of the width: a project card holds a name, a path and one metadata line, and those need a known number of columns to stay readable. Stretching cards to fill a wide modal would make three columns of mostly-empty box; shrinking them to fit a narrow one would truncate the path that makes a project recognisable. So the card keeps its size and the grid keeps whole columns, and below the width where even one card is readable the collection falls back to the list.

View Source
const (
	KindOverview = "overview"
	KindProject  = "project"
)

Destination kinds. Overview is the cross-project surface, not a project, and it is deliberately outside the sorting domain.

View Source
const UnknownLabel = "Unknown"

UnknownLabel is the word an absent timestamp reads as. It is a word and not a dash so the row says what is true rather than looking like a value failed to render.

Variables

SortModes is the offered set, in the order the sort menu lists them.

View Source
var ViewModes = []View{ViewList, ViewGrid}

ViewModes is the offered set, in control order.

Functions

func FormatDate

func FormatDate(t time.Time) string

FormatDate words a timestamp as a calendar date, which is what a registration date is actually read as. A zero time is UnknownLabel.

func FormatRelative

func FormatRelative(t, now time.Time) string

FormatRelative words a timestamp as an age. A zero time is UnknownLabel.

func GridAvailable

func GridAvailable(contentWidth int) bool

GridAvailable reports whether the grid can be drawn at this width at all. A view control that offers a layout the surface cannot draw is a control that lies, so the caller uses this to fall back rather than to refuse.

func GridColumns

func GridColumns(contentWidth int) int

GridColumns is how many card columns fit in contentWidth. Zero means not even one card is readable, which is the caller's signal to draw the list instead — the grid is an alternative view of the collection, never a worse one.

func GridMove

func GridMove(index, n, columns, dx, dy int) int

GridMove is the spatial arrow rule. Arrows in a grid move by position, not by list index: left and right walk the row, up and down change row keeping the column. Movement off the collection is refused rather than wrapped, so a press that has nowhere to go leaves the selection where the user put it.

dx and dy are -1, 0 or 1. The returned index is always within [0, n).

func GridRows

func GridRows(n, columns int) int

GridRows is how many card rows a collection of n items occupies.

func IndexOf

func IndexOf(items []Item, id string) int

IndexOf finds an item by identity. It returns -1 when the identity is gone, which is the caller's signal to fall back rather than land on a row the user did not choose.

func Matches

func Matches(item Item, query string) bool

Matches reports whether query is a case-insensitive substring of the item's name, path or host. An empty query matches everything.

func MetaColumn

func MetaColumn(mode Sort) (heading string, byDate bool)

MetaColumn is the heading and value the metadata column carries under a given sort. The column follows a date sort so the user can see what they ordered by; under Name it stays on last activity, which is the fact a switcher is most often opened to check.

func MetaValue

func MetaValue(item Item, mode Sort, now time.Time) string

MetaValue is one item's metadata cell under a given sort.

func OrderLabel

func OrderLabel(mode Sort, order Order) string

OrderLabel words the direction for the mode it applies to.

func SortActionID

func SortActionID(mode Sort) string

SortActionID names the choice a surface reports when a sort is picked, so a shared handler answers to one name rather than two.

func SortIndex

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

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

func ViewActionID

func ViewActionID(v View) string

ViewActionID names the choice a surface reports when a view is picked.

Types

type Item

type Item struct {
	// ID is the stable identity a selection rides through filtering, sorting
	// and a change of view. It must not encode position.
	ID   string
	Kind string
	// Name is the display name, host prefix included for a remote.
	Name string
	// Path is the destination's own root as its owner reports it. It is shown
	// and searched, never resolved locally for a remote.
	Path string
	// Host is the registered host id; empty is this machine.
	Host string
	// Current marks the destination this TUI is bound to. It is a status, not
	// a selection: the highlighted row is a separate concept.
	Current bool
	// DisabledReason is non-empty when the destination cannot be activated.
	// The row stays visible and says why.
	DisabledReason string
	// AddedAt is when the project was registered with Sidecar. Zero is
	// unknown, which is the honest answer for every project registered before
	// Sidecar started recording it.
	AddedAt time.Time
	// LastActiveAt is the latest recorded Sidecar activity in the project.
	// Zero is unknown.
	LastActiveAt time.Time
	Data         any
}

Item is one destination's resolved display identity. Every field is presentation input: this package matches, orders and formats from these values and reads nothing behind them. Data carries the caller's own record so a selection resolves back to its owner without this package knowing the type.

func Filter

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

Filter keeps the items a query matches, in the order handed in. Overview is filtered like anything else: a user who typed a query wants what they asked for, not a pinned row that ignores it.

func Sorted

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

Sorted returns the collection in the chosen order without mutating the input.

Three rules hold in every mode. Overview is not a project and stays pinned ahead of the collection. An unknown timestamp sorts last in both directions, because "we have not recorded this" is not a date and reversing the order must not promote it to the top. Ties break on the case-insensitive name and then the stable identity, so the same collection always produces the same order and a selection never jumps because two rows swapped.

func (Item) Disabled

func (i Item) Disabled() bool

Disabled reports whether the destination refuses activation.

type Order

type Order uint8

Order is the direction within a sort. The words differ by mode — a name has no "newest" — but the axis is one, so it persists and toggles as one.

const (
	OrderAscending Order = iota
	OrderDescending
)

func OrderFromLabel

func OrderFromLabel(label string) (Order, bool)

OrderFromLabel resolves a persisted direction label back to an Order. It accepts either mode's wording so a stored value survives the sort changing.

func (Order) Toggle

func (o Order) Toggle() Order

Toggle flips the direction.

type Sort

type Sort uint8

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

const (
	// SortActivity orders by the latest recorded Sidecar activity in the
	// project. It is first because recency is what a switcher is usually for.
	SortActivity Sort = iota
	SortName
	// SortAdded orders by when the project was registered with Sidecar. It is
	// "Date added" and not "Date created" on purpose: Sidecar records the
	// registration, and it knows nothing about when the directory or the
	// repository came into being.
	SortAdded
)

func SortFromAction

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

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

func SortFromLabel

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

SortFromLabel resolves a persisted label back to a mode, case-insensitively. Labels are what surfaces persist: they read plainly in a state file and survive the enum being reordered.

func (Sort) DefaultOrder

func (s Sort) DefaultOrder() Order

DefaultOrder is what a mode starts in: names read A–Z, dates read newest first, because that is what each is usually wanted for.

func (Sort) IsDate

func (s Sort) IsDate() bool

IsDate reports whether the mode orders by a timestamp, which is what decides the direction wording and whether unknown values are possible.

func (Sort) Label

func (s Sort) Label() string

Label is what the control reads and what a state file persists.

type View

type View uint8

View is the layout the collection is drawn in. It is a view of one ordered collection, not a second collection: selection, filter and order survive a change of view.

const (
	ViewList View = iota
	ViewGrid
)

func ViewFromAction

func ViewFromAction(action string) (View, bool)

ViewFromAction resolves an action ID back to a view.

func ViewFromLabel

func ViewFromLabel(label string) (View, bool)

ViewFromLabel resolves a persisted label back to a view.

func (View) Label

func (v View) Label() string

Jump to

Keyboard shortcuts

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