resourceview

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: 10 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 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

View Source
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.

View Source
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

func LayoutTabStrip(t *Tabs, width int, focused bool) tabs.Strip

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.

func TabKey

func TabKey(ref resource.Reference) string

TabKey is the stable identity of one tab before a resolve: the provider instance, the matcher, and the exact matched locator. The same locator from two providers is two resources, so the instance is part of the key.

Types

type Command

type Command struct {
	ID   string
	Key  string
	Name string
}

Command is one footer hint. ID is the keymap command the host registers under; Key is the default binding it documents.

func Commands

func Commands() []Command

Commands is the footer vocabulary for a focused Resource leaf. Both hosts register exactly this, so the two surfaces cannot advertise different keys for the same pane. Names are one word to keep the footer from wrapping.

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 New

func New(renderer *markdown.Renderer, resolve Resolver) *Model

New creates a view bound to a resolver. A nil renderer takes the default.

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

func (m *Model) Arm(modelID int, ref resource.Reference, epoch uint64)

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) Document

func (m *Model) Document() (resource.Document, bool)

Document returns the resolved document and whether there is one.

func (*Model) Err

func (m *Model) Err() *resource.Error

Err returns the current typed error, or nil.

func (*Model) Height

func (m *Model) Height() int

func (*Model) Load

func (m *Model) Load(modelID int, ref resource.Reference, epoch uint64) tea.Cmd

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

func (m *Model) ReArm() bool

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) Reference

func (m *Model) Reference() resource.Reference

Reference is what this tab points at.

func (*Model) Refresh

func (m *Model) Refresh() tea.Cmd

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

func (m *Model) Refreshing() bool

Refreshing reports an in-flight resolve over an existing document.

func (*Model) Rekey

func (m *Model) Rekey(identity string)

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

func (m *Model) Resolve() tea.Cmd

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) Scroll

func (m *Model) Scroll() int

Scroll is the current vertical offset, which the host persists.

func (*Model) ScrollAtBoundary

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

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

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

ScrollBy moves the viewport and reports whether anything moved, so a host can decide whether the wheel event was consumed.

func (*Model) ScrollTo

func (m *Model) ScrollTo(offset int) bool

ScrollTo jumps to an absolute offset.

func (*Model) SetPendingScroll

func (m *Model) SetPendingScroll(scroll int)

SetPendingScroll records a restored scroll offset to apply once there is something to scroll.

func (*Model) SetResolver

func (m *Model) SetResolver(resolve Resolver)

SetResolver replaces the host resolver used by subsequent loads. Existing armed tabs must observe provider setup that finishes after pane construction.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

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

func (m *Model) SourceURL() string

SourceURL is the one action a document can offer, already validated as http(s) by the document sanitizer.

func (*Model) State

func (m *Model) State() State

State reports what the view is showing.

func (*Model) TabLabel

func (m *Model) TabLabel() string

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.

func (*Model) Title

func (m *Model) Title() string

Title is the pane's headline for host chrome.

func (*Model) View

func (m *Model) View() string

View renders the card, held to exactly the box it was given. A content that hands back more rows than its box would push the app header off screen, so the fit is enforced here rather than trusted to the caller.

func (*Model) Width

func (m *Model) Width() int

Width and Height report the last box the view was given.

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 NewPane

func NewPane(tabs *Tabs, host Host) *Pane

NewPane binds a tab set to a surface.

func (*Pane) Activate

func (p *Pane) Activate(ref Ref) tea.Cmd

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

func (p *Pane) ActivateFromTerminal(ref Ref) tea.Cmd

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

func (p *Pane) CloseActiveTab() (empty bool, cmd tea.Cmd)

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) CycleTab

func (p *Pane) CycleTab(delta int) tea.Cmd

CycleTab moves through the strip, wrapping.

func (*Pane) HandleKey

func (p *Pane) HandleKey(key string) (handled bool, cmd tea.Cmd)

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

func (p *Pane) OpenSource() tea.Cmd

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

func (p *Pane) ReArmPending() int

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) Refresh

func (p *Pane) Refresh() tea.Cmd

Refresh re-resolves the active tab, bypassing cache freshness.

func (*Pane) Scroll

func (p *Pane) Scroll(delta int) bool

Scroll moves the active tab's viewport and reports whether it moved.

func (*Pane) ScrollAtBoundary

func (p *Pane) ScrollAtBoundary(delta int) bool

ScrollAtBoundary reports whether a scroll of delta would move the active tab.

func (*Pane) SelectTab

func (p *Pane) SelectTab(i int) tea.Cmd

SelectTab focuses a tab by index, resolving it if it was only armed.

type PersistedTab

type PersistedTab struct {
	Provider string
	Matcher  string
	Locator  string
	Scroll   int
}

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

type Ref = resource.Reference

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.
	SetResourceResolver(Resolver)
}

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 TabHit

type TabHit = tabs.Hit

TabHit is a drawn tab's click target, relative to the strip's first column.

type TabStrip

type TabStrip = tabs.Strip

TabStrip is the header row: only tabs, packed left to right.

type Tabs

type Tabs struct {
	tabs.Group[*Model]
	// contains filtered or unexported fields
}

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 NewTabs

func NewTabs(renderer *markdown.Renderer, resolve Resolver) *Tabs

NewTabs creates an empty tab set.

func (*Tabs) Active

func (t *Tabs) Active() *Model

Active returns the focused tab, or nil.

func (*Tabs) ActiveIndex

func (t *Tabs) ActiveIndex() int

ActiveIndex is the focused tab's position, which the host persists.

func (*Tabs) All

func (t *Tabs) All() []*Model

All returns the models in strip order.

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

func (t *Tabs) Arm(ref resource.Reference, scroll int) *Model

Arm appends a tab without resolving it. Restore uses this so relaunch does not fan out one process per remembered tab.

func (*Tabs) At

func (t *Tabs) At(i int) *Model

At returns the tab at index, or nil.

func (*Tabs) Close

func (t *Tabs) Close(i int) (empty bool)

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

func (t *Tabs) CloseActive() (empty bool)

CloseActive removes the focused tab.

func (*Tabs) Cycle

func (t *Tabs) Cycle(delta int) tea.Cmd

Cycle moves by delta and resolves the tab that lands, wrapping.

func (*Tabs) Empty

func (t *Tabs) Empty() bool

Empty reports whether the leaf has nothing left in it.

func (*Tabs) Labels

func (t *Tabs) Labels() []string

Labels is the tab strip's text, in order.

func (*Tabs) Len

func (t *Tabs) Len() int

Len reports how many tabs are open.

func (*Tabs) Next

func (t *Tabs) Next() tea.Cmd

Next and Prev are the documented { and } bindings.

func (*Tabs) Open

func (t *Tabs) Open(ref resource.Reference) tea.Cmd

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) Prev

func (t *Tabs) Prev() tea.Cmd

func (*Tabs) ReArmPending

func (t *Tabs) ReArmPending() int

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

func (t *Tabs) RefreshActive() tea.Cmd

RefreshActive re-resolves the active tab, bypassing freshness.

func (*Tabs) ResolveActive

func (t *Tabs) ResolveActive() tea.Cmd

ResolveActive starts the active tab's resolve if it is still armed.

func (*Tabs) SetActive

func (t *Tabs) SetActive(i int) tea.Cmd

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) SetEpoch

func (t *Tabs) SetEpoch(epoch uint64)

SetEpoch records the host's scoping value for subsequent loads.

func (*Tabs) SetResolver

func (t *Tabs) SetResolver(resolve Resolver)

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.

func (*Tabs) SetSize

func (t *Tabs) SetSize(width, height int)

SetSize sizes every tab, because a tab selected later must already know the box it will be drawn into.

func (*Tabs) View

func (t *Tabs) View() string

View renders the active tab.

Jump to

Keyboard shortcuts

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