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
- Variables
- func FormatDate(t time.Time) string
- func FormatRelative(t, now time.Time) string
- func GridAvailable(contentWidth int) bool
- func GridColumns(contentWidth int) int
- func GridMove(index, n, columns, dx, dy int) int
- func GridRows(n, columns int) int
- func IndexOf(items []Item, id string) int
- func Matches(item Item, query string) bool
- func MetaColumn(mode Sort) (heading string, byDate bool)
- func MetaValue(item Item, mode Sort, now time.Time) string
- func OrderLabel(mode Sort, order Order) string
- func SortActionID(mode Sort) string
- func SortIndex(mode Sort, modes []Sort) int
- func ViewActionID(v View) string
- type Item
- type Order
- type Sort
- type View
Constants ¶
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.
const ( KindOverview = "overview" KindProject = "project" )
Destination kinds. Overview is the cross-project surface, not a project, and it is deliberately outside the sorting domain.
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 ¶
var SortModes = []Sort{SortActivity, SortName, SortAdded}
SortModes is the offered set, in the order the sort menu lists them.
var ViewModes = []View{ViewList, ViewGrid}
ViewModes is the offered set, in control order.
Functions ¶
func FormatDate ¶
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 ¶
FormatRelative words a timestamp as an age. A zero time is UnknownLabel.
func GridAvailable ¶
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 ¶
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 ¶
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 IndexOf ¶
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 ¶
Matches reports whether query is a case-insensitive substring of the item's name, path or host. An empty query matches everything.
func MetaColumn ¶
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 OrderLabel ¶
OrderLabel words the direction for the mode it applies to.
func SortActionID ¶
SortActionID names the choice a surface reports when a sort is picked, so a shared handler answers to one name rather than two.
func ViewActionID ¶
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 ¶
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 ¶
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.
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.
func OrderFromLabel ¶
OrderFromLabel resolves a persisted direction label back to an Order. It accepts either mode's wording so a stored value survives the sort changing.
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 ¶
SortFromAction resolves an action ID back to a mode within the offered set.
func SortFromLabel ¶
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 ¶
DefaultOrder is what a mode starts in: names read A–Z, dates read newest first, because that is what each is usually wanted for.
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.
func ViewFromAction ¶
ViewFromAction resolves an action ID back to a view.
func ViewFromLabel ¶
ViewFromLabel resolves a persisted label back to a view.