Documentation
¶
Overview ¶
Package contentlink recognizes activatable references in rendered text.
Recognition is presentation-neutral and side-effect free. Callers provide ready resolver snapshots; unresolved candidates are returned as pending work for a later command rather than resolved during rendering.
Index ¶
- Constants
- func Activatable(k Kind) bool
- func Decorate(line string, spans []Span) string
- func IssueID(value string) bool
- func NoteID(value string) bool
- func SafeHTTPURL(raw string) (string, bool)
- func SessionName(value string) bool
- func StripOSC8(line string) string
- func WrapVisualRange(line string, startCol, endCol int, open, close string) string
- type DiffResolver
- type Extra
- type FrameOptions
- type FrameResult
- type InternalURI
- type Kind
- type KindSet
- type Options
- type Pending
- type Ref
- type ResolutionIndex
- type ResolutionSnapshot
- type Resolver
- type ResourceMatcher
- type Span
- type Surface
- type URIOptions
Constants ¶
const ( MaxNewDiffResolves = 16 MaxResourceLocatorChars = 200 MaxResourceMatchesPerLine = 32 MaxAutomaticMatchesPerLine = 64 MaxRenderedRows = 1000 MaxRenderedColumns = 4096 MaxPendingResolutions = 128 MaxInternalURIBytes = 2048 MaxInternalNamespaceBytes = 32 MaxInternalIDRunes = 512 MaxInternalQueryParameters = 16 MaxInternalQueryKeyBytes = 32 MaxInternalQueryValueRunes = 256 MaxExplicitLabelColumns = 4096 // MaxExplicitDestinationBytes bounds a source-supplied OSC-8 URI before // contentlink retains it in a Span or resynthesizes it into rendered output. // The destination is zero-width terminal control data, so the rendered // column limit cannot bound it. MaxExplicitDestinationBytes = 2048 )
Variables ¶
This section is empty.
Functions ¶
func Activatable ¶
Activatable reports whether hosts may bind and decorate the kind.
func Decorate ¶
Decorate underlines local references and synthesizes OSC-8 for safe HTTP(S) destinations: built-in URL spans, and resource spans whose locator is itself a browser URL — a claimed GitHub URL must keep its emulator hyperlink so cmd-click remains the escape hatch even after Sidecar reclassifies the span. Resource locators that are keys or refs stay underline-only.
Source OSC must first be removed by StripOSC8 or ScanFrame.
func SafeHTTPURL ¶
SafeHTTPURL trims prose punctuation and accepts only http(s), with a host and no controls.
func SessionName ¶
SessionName reports whether value is a Sidecar-owned attachable tmux session name. Stored notification targets use the same validation as scans.
Types ¶
type Extra ¶
Extra preserves the terminal-link scanner's original public shape while callers migrate to Ref. Raw is the token as rendered before ready resolution.
type FrameOptions ¶
type FrameOptions struct {
Ready ResolutionSnapshot
Matchers []ResourceMatcher
InternalNamespaces map[string]URIOptions
// AllowedKinds bounds the kinds returned, decorated, and queued for
// resolution. Nil preserves the scanner's all-kinds default; a non-nil
// empty set allows none. Explicit OSC labels still claim their cells when
// their destination kind is excluded, so automatic matching cannot turn a
// disallowed explicit destination into a different action.
//
// Claim interaction: URL yield runs before this filter, so a surface that
// allows KindURL but not KindResource would drop claimed URLs entirely —
// inert text where a browser link used to be. Every current scanning
// surface advertises both kinds together (docview.ContentLinkKinds is the
// shared set, pinned by test); a future surface wanting one without the
// other must decide what claimed URLs should do first.
AllowedKinds KindSet
Decorate bool
}
type FrameResult ¶
func ScanFrame ¶
func ScanFrame(frame string, opts FrameOptions) FrameResult
ScanFrame recognizes a bounded, already-rendered ANSI frame. Explicit OSC-8 spans are extracted first and beat automatic matches. File and diff matching consults only Ready; misses become bounded, deduplicated Pending work.
type InternalURI ¶
InternalURI carries the stable intent reference and handler-owned options. Query is copied and may be safely retained by a handler.
func ParseInternalURI ¶
func ParseInternalURI(raw string) (InternalURI, error)
func ParseInternalURIWith ¶
func ParseInternalURIWith(raw string, opts URIOptions) (InternalURI, error)
type Kind ¶
type Kind string
Kind classifies an activatable reference.
const ( KindURL Kind = "url" KindFile Kind = "file" KindIssue Kind = "issue" KindDiff Kind = "diff" KindResource Kind = "resource" KindInternal Kind = "internal" // KindSession identifies a Sidecar-owned tmux session that a host can // attach. Only names Sidecar itself mints are recognized from text. KindSession Kind = "session" )
type KindSet ¶
type KindSet map[Kind]struct{}
KindSet bounds the reference kinds a rendered surface allows the host to recognize. The zero value allows none.
func NewKindSet ¶
NewKindSet constructs a set containing kinds.
type Options ¶
type Options struct {
Resolve Resolver
ResolveDiff DiffResolver
Matchers []ResourceMatcher
}
type Pending ¶
Pending names side-effecting work a caller may run after rendering. Only file and diff candidates are produced. Raw is the exact rendered token.
type Ref ¶
Ref is the presentation-neutral identity produced by every recognition path. Line is 1-based and zero when absent. Provider and Matcher identify an external resource matcher. Namespace is set only for internal intents.
type ResolutionIndex ¶
type ResolutionIndex struct {
// contains filtered or unexported fields
}
ResolutionIndex is a bounded per-surface cache. Resolution work happens outside this type; Put applies its result on the update path, and Snapshot gives View a side-effect-free copy.
func NewResolutionIndex ¶
func NewResolutionIndex(limit int) *ResolutionIndex
func (*ResolutionIndex) Put ¶
func (i *ResolutionIndex) Put(candidate Pending, ref Ref, found bool) bool
func (*ResolutionIndex) Reset ¶
func (i *ResolutionIndex) Reset()
func (*ResolutionIndex) Snapshot ¶
func (i *ResolutionIndex) Snapshot() ResolutionSnapshot
type ResolutionSnapshot ¶
type ResolutionSnapshot struct {
// contains filtered or unexported fields
}
ResolutionSnapshot is an immutable ready-only view used during rendering. A missing key means unresolved, not a negative result.
type Resolver ¶
Resolver and DiffResolver are the legacy synchronous scanner hooks. New rendered surfaces should use ScanFrame with a ResolutionSnapshot instead.
type ResourceMatcher ¶
ResourceMatcher is one live external matcher. The whole match is the locator.
ClaimHosts carries the matcher's instance configuration: the lowercased hostnames whose built-in URL spans that instance may reclassify into resource spans. It is empty for an instance that claims nothing, and it never widens what Re itself matches — a URL is yielded only when its host is listed here AND Re matches the entire URL string. Built-in precedence is not inverted anywhere else.
type Span ¶
type Span struct {
Kind Kind
Row int
StartCol int
EndCol int
Value string
Extra Extra
Explicit bool
}
Span is one non-overlapping reference in inclusive visual columns. Row is zero for a line scan and the zero-based rendered row for a frame scan.
func ScanWith ¶
ScanWith preserves the existing synchronous terminal scanner contract. Built-ins win in URL, path:line, file, issue, diff, resource order.
func SpanForRef ¶
SpanForRef constructs a coordinate-free span. It is useful at adapters that still consume the compatibility Span vocabulary.
type Surface ¶
type Surface struct {
ID string
Rect mouse.Rect
WorkDir string
ProjectRoot string
Kinds KindSet
ReadOnly bool
}
Surface describes one exact, already-rendered text rectangle that a host may scan for content links. Rect uses plugin-local coordinates.
type URIOptions ¶
type URIOptions struct {
AllowedQuery map[string]struct{}
// ValidateID applies namespace-owned identity rules after generic URI
// decoding and bounds checks. A nil validator accepts any generic ID.
ValidateID func(string) bool
}
URIOptions is the generic parser's query allowlist. The zero value accepts no query parameters. Namespace handlers choose their own bounded keys.