Documentation
¶
Overview ¶
Package resourceview renders one external resource document in one content box, and a tabbed set of them in one pane leaf.
It is deliberately host-independent. It knows about resource.Document, resource.Reference and resource.Error and nothing about panes, tmux, workspaces, projects, or which of the two terminal surfaces is showing it. The project Workspace and the global Workspaces browser both bind it, and anything that behaves differently between them is a bug rather than a preference.
It is also passive. A provider supplies data, never presentation: no ANSI, no keybindings, no actions, no colors. The one thing a document can do is name a validated http(s) source URL, and even that is opened by the host through its own confirmed path.
Resolution happens elsewhere. The view asks for a reference to be resolved by returning a command the host supplies; it never starts a process itself, which is what keeps process work out of View and Update.
Index ¶
- Constants
- func LayoutTabStrip(t *Tabs, width int, focused bool) tabs.Strip
- func TabKey(ref resource.Reference) string
- type Command
- type Host
- type Model
- func (m *Model) Accepts(msg ResolvedMsg) bool
- func (m *Model) Apply(msg ResolvedMsg) bool
- func (m *Model) Arm(modelID int, ref resource.Reference, epoch uint64)
- func (m *Model) Document() (resource.Document, bool)
- func (m *Model) Err() *resource.Error
- func (m *Model) Height() int
- func (m *Model) Load(modelID int, ref resource.Reference, epoch uint64) tea.Cmd
- func (m *Model) ReArm() bool
- func (m *Model) Reference() resource.Reference
- func (m *Model) Refresh() tea.Cmd
- func (m *Model) Refreshing() bool
- func (m *Model) Rekey(identity string)
- func (m *Model) Resolve() tea.Cmd
- func (m *Model) Scroll() int
- func (m *Model) ScrollAtBoundary(delta int) bool
- func (m *Model) ScrollBy(delta int) bool
- func (m *Model) ScrollTo(offset int) bool
- func (m *Model) SetPendingScroll(scroll int)
- func (m *Model) SetResolver(resolve Resolver)
- func (m *Model) SetSize(width, height int)
- func (m *Model) SourceURL() string
- func (m *Model) State() State
- func (m *Model) TabLabel() string
- func (m *Model) Title() string
- func (m *Model) View() string
- func (m *Model) Width() int
- type Pane
- func (p *Pane) Activate(ref Ref) tea.Cmd
- func (p *Pane) ActivateFromTerminal(ref Ref) tea.Cmd
- func (p *Pane) Apply(msg ResolvedMsg) bool
- func (p *Pane) CloseActiveTab() (empty bool, cmd tea.Cmd)
- func (p *Pane) CloseTab(i int) (empty bool, cmd tea.Cmd)
- func (p *Pane) CycleTab(delta int) tea.Cmd
- func (p *Pane) HandleKey(key string) (handled bool, cmd tea.Cmd)
- func (p *Pane) OpenSource() tea.Cmd
- func (p *Pane) ReArmPending() int
- func (p *Pane) Refresh() tea.Cmd
- func (p *Pane) Scroll(delta int) bool
- func (p *Pane) ScrollAtBoundary(delta int) bool
- func (p *Pane) SelectTab(i int) tea.Cmd
- type PersistedTab
- type Ref
- type ResolvedMsg
- type Resolver
- type State
- type Surface
- type TabHit
- type TabStrip
- type Tabs
- func (t *Tabs) Active() *Model
- func (t *Tabs) ActiveIndex() int
- func (t *Tabs) All() []*Model
- func (t *Tabs) Apply(msg ResolvedMsg) bool
- func (t *Tabs) Arm(ref resource.Reference, scroll int) *Model
- func (t *Tabs) At(i int) *Model
- func (t *Tabs) Close(i int) (empty bool)
- func (t *Tabs) CloseActive() (empty bool)
- func (t *Tabs) Cycle(delta int) tea.Cmd
- func (t *Tabs) Empty() bool
- func (t *Tabs) Labels() []string
- func (t *Tabs) Len() int
- func (t *Tabs) Next() tea.Cmd
- func (t *Tabs) Open(ref resource.Reference) tea.Cmd
- func (t *Tabs) Prev() tea.Cmd
- func (t *Tabs) ReArmPending() int
- func (t *Tabs) References() []PersistedTab
- func (t *Tabs) RefreshActive() tea.Cmd
- func (t *Tabs) ResolveActive() tea.Cmd
- func (t *Tabs) SetActive(i int) tea.Cmd
- func (t *Tabs) SetEpoch(epoch uint64)
- func (t *Tabs) SetResolver(resolve Resolver)
- func (t *Tabs) SetSize(width, height int)
- func (t *Tabs) View() string
Constants ¶
const ( CommandRefresh = "refresh" CommandOpenSource = "open-source" CommandPrevTab = "prev-tab" CommandNextTab = "next-tab" CommandCloseTab = "close-tab" )
Stable command IDs for a Resource leaf. They are declared here, not derived per host, because the footer resolves a hint's key through the keymap by ID: two hosts inventing their own IDs is two surfaces advertising different keys for one pane. They follow the vocabulary the other panes already use — prev-tab/next-tab rather than one combined "{/}" command, which is a rule TestBracesAlwaysMeanTabCycling enforces repo-wide.
const MaxTabs = 16
MaxTabs bounds one Resource leaf. Clicking keys forever must cost bounded memory and a bounded tab strip; past the bound the oldest unfocused tab is dropped rather than refusing the user's click.
Variables ¶
This section is empty.
Functions ¶
func LayoutTabStrip ¶
LayoutTabStrip is the Resource leaf's header row. Both hosts draw this and register their hit regions from the same result, so a click cannot land on a tab that was never rendered.
Types ¶
type Command ¶
Command is one footer hint. ID is the keymap command the host registers under; Key is the default binding it documents.
type Host ¶
type Host interface {
// FocusLeaf moves focus to the leaf holding this pane. It is called on
// every activation, including one that only focuses an existing tab.
FocusLeaf()
// EnterFromTerminal is the ritual a click in terminal output owes before
// a new leaf appears: clear the selection, leave interactive input, and
// freeze the terminal viewport so the pre-click context survives the
// tmux resize. A surface with no live terminal implements it as a no-op.
EnterFromTerminal()
// Persist records reference-only tab state. The global surface implements
// it as a no-op; that difference is the intended one.
Persist()
// OpenURL puts a validated http(s) URL in front of the user through the
// host's own confirmed path.
OpenURL(url string) tea.Cmd
}
Host is everything a Resource leaf needs from the surface showing it, and deliberately nothing more. Each method is a place the project Workspace and the global Workspaces browser genuinely differ:
- the project has a pane tree with leaf IDs; the global has one preview slot;
- the project persists references to disk; the global is memory-only by design, matching its document/issue/diff lifetime;
- only the project has a live tmux pane to abandon and an interactive input mode to leave.
Everything that does NOT differ lives on Pane below, so neither surface can answer a resource key differently from the other by accident.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is one resource reference in one content box.
func (*Model) Accepts ¶
func (m *Model) Accepts(msg ResolvedMsg) bool
Accepts reports whether a result belongs to this model's current request. A host still applies its own surface and epoch checks; this is the part every host would otherwise have written for itself.
func (*Model) Apply ¶
func (m *Model) Apply(msg ResolvedMsg) bool
Apply lands a resolve result. It returns false when the message does not belong to this model's current request, which is the normal outcome for a superseded refresh or a closed-and-reopened tab.
func (*Model) Arm ¶
Arm points the model at a reference without resolving it. A restored tab starts here so that opening Sidecar does not fan out one process per tab.
func (*Model) Load ¶
Load resolves the reference, replacing whatever the model was showing. It bumps the generation, so any answer already in flight is stale on arrival.
func (*Model) ReArm ¶
ReArm returns a tab that is waiting on an answer nobody will deliver to the armed state, and reports whether it changed anything.
A host discards a result whose surface, workspace row, or project epoch no longer matches. That is correct — but without this the tab it belonged to sits on a loading card forever, because the answer that would have cleared it was thrown away. Re-arming bumps the generation, so the discarded answer can never land afterwards either, and the card goes back to saying the tab is remembered and can be resolved with r.
func (*Model) Refresh ¶
Refresh re-resolves, bypassing freshness. Scroll and the last good document are preserved: a transient failure must not blank a card the user is reading.
func (*Model) Refreshing ¶
Refreshing reports an in-flight resolve over an existing document.
func (*Model) Rekey ¶
Rekey adopts the provider-stable identity a response supplied. The provider instance is never allowed to change: a response may say what a resource is called, not who owns it.
func (*Model) Resolve ¶
Resolve starts a resolve for an armed tab, and is a no-op for one that is already loading or resolved. Selecting a restored tab calls this.
func (*Model) ScrollAtBoundary ¶
ScrollAtBoundary reports whether a scroll of delta would move nothing, which is how a host decides to hand a wheel event to whatever is underneath instead of swallowing it. The doc, issue and diff viewers all answer this; without it a host has to probe by scrolling and undoing.
func (*Model) ScrollBy ¶
ScrollBy moves the viewport and reports whether anything moved, so a host can decide whether the wheel event was consumed.
func (*Model) SetPendingScroll ¶
SetPendingScroll records a restored scroll offset to apply once there is something to scroll.
func (*Model) SetResolver ¶
SetResolver replaces the host resolver used by subsequent loads. Existing armed tabs must observe provider setup that finishes after pane construction.
func (*Model) SetSize ¶
SetSize records the content box. The body is re-rendered lazily on the next View, because a resize during a drag would otherwise re-run the markdown renderer on every frame of the drag.
func (*Model) SourceURL ¶
SourceURL is the one action a document can offer, already validated as http(s) by the document sanitizer.
func (*Model) TabLabel ¶
TabLabel is what the tab strip shows: the locator, which is stable from the moment of the click, rather than a title that appears a moment later and makes the strip jump.
type Pane ¶
type Pane struct {
Tabs *Tabs
// contains filtered or unexported fields
}
Pane is the host-independent behavior of one Resource leaf: what a click does, what the documented keys do, and when state is persisted.
Both surfaces own a Pane and implement Host. A binding that reimplements one of these methods instead of calling it is the drift this type exists to prevent.
func (*Pane) Activate ¶
Activate opens or focuses a tab without the terminal ritual. This is the `sidecar open --provider` path: there was no click in terminal output, so there is no selection to clear and no viewport to freeze.
func (*Pane) ActivateFromTerminal ¶
ActivateFromTerminal is the click journey: the terminal ritual first, then focus, then open-or-focus the tab, then persist. The order matters — the viewport must be frozen before the new leaf resizes tmux — and getting it right once here is the point.
func (*Pane) Apply ¶
func (p *Pane) Apply(msg ResolvedMsg) bool
Apply routes a resolve result and persists the outcome, since a canonical re-key changes what should be on disk.
func (*Pane) CloseActiveTab ¶
CloseActiveTab closes the focused tab and reports whether the leaf is now empty, which is the host's cue to collapse the split.
func (*Pane) CloseTab ¶ added in v1.3.0
CloseTab closes the tab at index through the same last-tab empty report.
func (*Pane) HandleKey ¶
HandleKey answers the documented Resource-pane keys. It deliberately does NOT claim q or esc: those follow each surface's existing content-pane close/hide rule, which is the one key behavior that legitimately differs.
handled=false means the host should keep looking.
func (*Pane) OpenSource ¶
OpenSource opens the active document's validated source URL. A document without one, or a tab that has not resolved, does nothing.
func (*Pane) ReArmPending ¶
ReArmPending is the counterpart to a host discarding results in bulk. Call it wherever results stop being routed — a workspace row switch, a project change — so a tab is never stranded on a loading card.
func (*Pane) ScrollAtBoundary ¶
ScrollAtBoundary reports whether a scroll of delta would move the active tab.
type PersistedTab ¶
PersistedTab is one reference plus its scroll. It mirrors the state package's JSON shape without this package depending on state, so the view layer stays free of persistence concerns.
type Ref ¶
Ref is the resource reference a tab points at. It is aliased rather than redeclared so a reference built by the scanner, restored from disk, or parsed from a CLI request is the same type everywhere.
func ReferenceForLocator ¶
func ReferenceForLocator(matchers []terminallink.ResourceMatcher, provider, locator string) (Ref, string)
ReferenceForLocator chooses the first live matcher from provider whose whole match is locator. UI requests intentionally carry no matcher ID: the running app is the authority for the provider snapshot and its declared precedence.
type ResolvedMsg ¶
type ResolvedMsg struct {
ModelID int
Generation uint64
// Epoch is the host's own scoping value, carried through untouched.
Epoch uint64
// Ref is the reference that was requested, before any canonical re-key.
Ref resource.Reference
Document resource.Document
Err error
// Refresh marks a result produced by Refresh rather than the first load,
// so a failure can leave the last good document on screen.
Refresh bool
}
ResolvedMsg is the result of one resolve. Its identity fields are what stop a late answer from landing in a closed, retargeted, or foreign tab: the host adds its own surface and epoch scoping on top.
func (ResolvedMsg) GetEpoch ¶
func (m ResolvedMsg) GetEpoch() uint64
GetEpoch lets hosts run their normal epoch check without unwrapping.
type Resolver ¶
type Resolver func(modelID int, generation, epoch uint64, ref resource.Reference, refresh bool) tea.Cmd
Resolver is how the view asks the host to resolve a reference. The host owns the manager, the process, the timeout and the cancellation; the view owns only when to ask and what to do with the answer.
refresh bypasses cache freshness. The returned command must eventually produce a ResolvedMsg carrying the same identity fields it was given.
epoch is the host's own scoping value, passed through so the model stamps it rather than every host wrapping the resolver to do the same thing.
type State ¶
type State int
State is what the view is showing right now.
const ( // StateArmed is a reference that has never been resolved: a restored tab // that has not been selected, or one whose provider is not ready yet. It // is not an error and must never be pruned as though it were. StateArmed State = iota // StateLoading is a resolve in flight with nothing to show behind it. StateLoading // StateReady is a resolved document. StateReady // StateError is a typed failure with no document behind it. StateError )
type Surface ¶
type Surface interface {
// SetResourceMatchers publishes the live matcher snapshot. An empty slice
// is meaningful: it is how output goes back to being ordinary text.
SetResourceMatchers([]terminallink.ResourceMatcher)
// SetResourceResolver injects how a reference becomes a document, and
// returns the work that injection starts.
//
// Returning a command is the point, not a convenience. A tab restored
// before any provider was ready is armed, and its card promises it resolves
// when the provider reports ready. Readiness arrives here and nowhere else,
// so a surface that only rebound its tabs would leave that promise unkept
// and the user re-resolving every tab by hand after each relaunch. A
// surface with nothing on screen waiting returns nil.
SetResourceResolver(Resolver) tea.Cmd
}
Surface is what the app injects provider state into. It is declared here rather than in the app so each surface can assert it at compile time:
var _ resourceview.Surface = (*Plugin)(nil)
The app reaches surfaces through a type assertion, and an assertion that quietly fails is a surface that never receives a matcher — the pane would simply never appear, with nothing to debug. The assertion in each package is what turns that into a build error.
type Tabs ¶
Tabs is the tabbed set of resource references in one Resource leaf.
Ordering, cycling, close semantics and the overflow window come from tabs.Group, the same generic the file and issue strips use. What this type adds is only what is specific to resources: keys built from references, arming without resolving, routing an answer to the tab that asked, and the canonical re-key that merges two tabs naming one resource.
func (*Tabs) ActiveIndex ¶
ActiveIndex is the focused tab's position, which the host persists.
func (*Tabs) Apply ¶
func (t *Tabs) Apply(msg ResolvedMsg) bool
Apply routes a resolve result to the tab that asked for it, applies any canonical re-key, and merges a tab that has just become a duplicate.
It returns false when no open tab owns the message, which is the correct outcome for a result arriving after its tab was closed.
func (*Tabs) Arm ¶
Arm appends a tab without resolving it. Restore uses this so relaunch does not fan out one process per remembered tab.
func (*Tabs) Close ¶
Close removes the tab at index and reports whether the leaf is now empty. Closing is the user's explicit act, and with a confirmed cleanup it is the only thing that may drop a reference.
func (*Tabs) CloseActive ¶
CloseActive removes the focused tab.
func (*Tabs) Open ¶
Open focuses an existing tab for ref, or appends a new one and resolves it. It is the single entry point for a terminal click, a restored tab being selected, and `sidecar open --provider`, so all three behave identically.
func (*Tabs) ReArmPending ¶
ReArmPending returns every tab waiting on an answer the host has decided to discard back to a resolvable state, and reports how many changed. A host calls this when it drops results wholesale — a workspace row switch, a project change — so no tab is left on a loading card forever.
func (*Tabs) References ¶
func (t *Tabs) References() []PersistedTab
References is the reference-only projection the project surface persists: no title, field, body, error, URL, or auth state, by construction rather than by remembering to strip them.
func (*Tabs) RefreshActive ¶
RefreshActive re-resolves the active tab, bypassing freshness.
func (*Tabs) ResolveActive ¶
ResolveActive starts the active tab's resolve if it is still armed.
func (*Tabs) SetActive ¶
SetActive focuses a tab by index and resolves it if it is still armed. Selecting is what turns a restored reference into a request, which is the behavior both hosts need and neither should re-derive.
func (*Tabs) SetResolver ¶
SetResolver replaces the resolver for this set and every existing tab. Provider setup is asynchronous, so resolver injection must not depend on whether a restored or clicked tab happened to be constructed first.