remoteview

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package remoteview is the machinery pkg/table and pkg/eventlog share for showing data that lives behind a slow remote source: which query the items on screen answer, whether that is still the one the user committed, what failed, what the border says about it, and — in Range — which items are resident at all.

It holds state and answers questions; it renders nothing and owns no component. Each host keeps its own cursor, rendering and query model, and asks this package the questions that must be answered the same way in every component that shows remote data: are these items stale, what does the border suffix read, is a spinner due.

Index

Constants

View Source
const FrameEvery = 90 * time.Millisecond

FrameEvery is how often the suffix spinner advances.

Variables

View Source
var Frames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

Frames is the spinner drawn in the border suffix.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Raw  string
	Sort string
	Desc bool
}

Answer names the query a set of items answers: the committed filter text, the sort column's title, and its direction. Hosts export it under their own name (table.Answer, eventlog.Answer) as an alias.

func (Answer) Label

func (a Answer) Label(asc, desc string) string

Label renders the query for the border suffix.

func (Answer) Normalized

func (a Answer) Normalized() Answer

Normalized is a with the forms that mean the same query made equal.

type Missing

type Missing struct {
	First, Last int
	OK          bool
}

Missing is a run of items on screen that are not resident.

type Range

type Range[T any] struct {
	// contains filtered or unexported fields
}

Range is the items a component holds of a remote set: a contiguous run, each with a key, either at logical offsets of a Seekable set (with a total) or as a Span of Anchored data (no offsets, more-or-not at each edge). It grows by merging pages, trims the end furthest from the viewport past a cap, and answers "is logical index i resident".

func NewRange

func NewRange[T any]() Range[T]

NewRange returns an empty Seekable range.

func NewSpan

func NewSpan[T any]() Range[T]

NewSpan returns an empty span, with more beyond both edges until pages say otherwise.

func (*Range[T]) Append

func (r *Range[T]) Append(items []T, keys []string, at int) (before int)

Append adds items at the newer edge of a span (or the end of a range), oldest first. Keys already held are skipped; an item the page places before a held key — a late arrival — goes before it, so the result keeps the page's own order without comparing cursors. It reports how many items were inserted before index at, so a host can keep its cursor.

func (Range[T]) At

func (r Range[T]) At(i int) (T, bool)

At returns logical item i, and false when it isn't resident.

func (*Range[T]) Clear

func (r *Range[T]) Clear()

Clear drops everything held.

func (Range[T]) Count

func (r Range[T]) Count() int

Count is the logical length: the total when known, else what is held through its end. For a span it is the resident length.

func (Range[T]) Edges

func (r Range[T]) Edges() (older, newer string)

Edges returns the keys of the oldest and newest resident items — the cursors an Anchored source extends from.

func (Range[T]) Held

func (r Range[T]) Held() (start, count int)

Held reports the logical start and length of what is resident.

func (Range[T]) IndexOf

func (r Range[T]) IndexOf(k string) int

IndexOf returns the logical index of the item keyed k, or -1.

func (Range[T]) IsSpan

func (r Range[T]) IsSpan() bool

IsSpan reports whether the range is a span of Anchored data.

func (Range[T]) KeyAt

func (r Range[T]) KeyAt(i int) string

KeyAt returns logical item i's key, or "".

func (Range[T]) Len

func (r Range[T]) Len() int

Len is how many items are resident.

func (*Range[T]) Merge

func (r *Range[T]) Merge(items []T, keys []string, offset, total int)

Merge installs a Seekable page: one that touches or overlaps what is held extends it (the page wins where they overlap), one that doesn't replaces it.

func (Range[T]) More

func (r Range[T]) More() (older, newer bool)

More reports whether each edge of a span has more beyond it.

func (*Range[T]) Prepend

func (r *Range[T]) Prepend(items []T, keys []string, at int) (before int)

Prepend adds items at the older edge, oldest first, merged the same way.

func (*Range[T]) Replace

func (r *Range[T]) Replace(items []T, keys []string, offset, total int)

Replace installs items as the whole range, at offset of a set total long (Seekable; ignored for a span).

func (*Range[T]) SetMore

func (r *Range[T]) SetMore(older, newer bool)

SetMore sets whether each edge of a span has more beyond it.

func (Range[T]) Total

func (r Range[T]) Total() int

Total is the reported total, or -1.

func (*Range[T]) Trim

func (r *Range[T]) Trim(max, first, last int) (front int)

Trim drops items past max from the end furthest from the viewport [first, last] (logical indices), and reports how many went from the front. A trimmed span edge has more beyond it again.

type Status

type Status struct {
	Answer    Answer
	HasAnswer bool
	Failed    bool
	// Retry marks that committing the unchanged, failed query again must
	// still be reported, since that is how the user retries it.
	Retry bool
	// contains filtered or unexported fields
}

Status is where a host stands with its source: the query its items answer, whether the committed query failed, and a page failure scoped to the items that were missing when it happened.

func (*Status) AnswerCommitted

func (s *Status) AnswerCommitted(committed Answer)

AnswerCommitted records that items installed with no Answer — a host's plain setters — answer the committed query.

func (*Status) Arm

func (s *Status) Arm(token focus.Token, waiting bool) tea.Cmd

Arm returns the next spinner tick when waiting and none is armed.

func (*Status) Handle

func (s *Status) Handle(token focus.Token, msg tea.Msg) (handled, advanced bool)

Handle consumes the host's spinner tick. handled is true for any TickMsg; advanced is true when it was this host's current tick and the frame moved, so the host should redraw and re-arm.

func (Status) Loading

func (s Status) Loading() bool

Loading reports whether the host's body should show its Loading spinner: nothing has answered yet, and nothing has failed.

func (Status) PageFailed

func (s Status) PageFailed(missing Missing) bool

PageFailed reports whether the items missing now are the ones whose page failed.

func (*Status) Rearm

func (s *Status) Rearm()

Rearm forgets any spinner tick in flight, so the next Arm schedules a fresh one — for a Status carried onto a rebuilt host, whose ticks the old host's pending one will not match.

func (*Status) SetAnswer

func (s *Status) SetAnswer(a, committed Answer) (fresh bool)

SetAnswer records that newly installed items answer a. It reports whether they end a stale spell — the moment a host moves its cursor to where the new answer begins.

func (*Status) SetFailed

func (s *Status) SetFailed(q, committed Answer, missing Missing)

SetFailed records a failed fetch for q. A failure for anything but the committed query is already superseded and ignored. When the committed query is answered and current, only a page of it failed: that failure is scoped to the items missing now, and is not a failed query.

func (Status) Spin

func (s Status) Spin() string

Spin reports the current spinner frame, for hosts drawing other waiting states (an edge loading) with the same glyph.

func (Status) Stale

func (s Status) Stale(committed Answer) bool

Stale reports whether the items answer a query other than committed.

func (Status) Suffix

func (s Status) Suffix(committed Answer, missing Missing, noun, asc, desc string) string

Suffix is the border text after the host's title, or "" when there is nothing to say. noun names what is missing ("rows", "items").

func (Status) Waiting

func (s Status) Waiting(committed Answer, missing Missing) bool

Waiting reports whether the border is showing a spinner: stale items waiting on the committed query, or items on screen not yet resident.

type TickMsg

type TickMsg struct {
	Token focus.Token
	Seq   int
}

TickMsg advances a host's suffix spinner.

Jump to

Keyboard shortcuts

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