Documentation
¶
Overview ¶
Package terminallink detects URL, file, issue, and git-spec spans in terminal text.
Detection lives here so the project Workspaces plugin and the global Workspaces preview share one matcher. Hosts activate the kinds they understand and ignore the rest. Adding a kind therefore does not require editing two hosts.
KindIssue is emitted for td-<hex> ids so a later terminal | file + td split can bind a live td pane. It must not open internal/app/issue_preview.go. KindDiff is emitted for existence-gated lowercase hex revs, "commit <rev>", and A..B / A...B ranges. HEAD and branch names are not scanned.
Index ¶
- Constants
- func Decorate(line string, spans []Span) string
- func IssueID(value string) bool
- func Markdown(path string) bool
- func OpenHTTP(raw string) tea.Cmd
- func OpenRegular(absolute string) (*os.File, error)
- func ResolveCommit(workdir, rev string) (oid string, ok bool)
- func ResolveFile(base, raw string) (display, absolute string, ok bool)
- func SafeHTTPURL(raw string) (string, bool)
- func StripOSC8(line string) string
- func WrapVisualRange(line string, startCol, endCol int, open, close string) string
- type DiffResolver
- type Extra
- type Kind
- type Resolver
- type Span
Constants ¶
const MaxNewDiffResolves = 16
MaxNewDiffResolves is the host budget for new git existence checks per (surface, buffer revision). Further unique spec tokens stay plain text until the next revision.
Variables ¶
This section is empty.
Functions ¶
func Decorate ¶
Decorate underlines file, issue, and git-spec spans and synthesizes OSC-8 for validated URLs. A host passes only the kinds it binds — an underline no click can honor is a dead link, and which kinds a host binds is the host's own answer. Callers must StripOSC8 first.
func IssueID ¶ added in v0.99.0
IssueID reports whether value is a td id of the shape this package detects. A host that restores an id from disk asks here rather than trusting the file: the click path can only ever produce this shape, and the id becomes an argv element of the fetch.
func OpenRegular ¶
OpenRegular opens the EvalSymlinks result of absolute when it is a regular file. Callers own the returned handle.
func ResolveCommit ¶ added in v1.0.0
ResolveCommit reports whether rev names a commit in workdir.
func ResolveFile ¶
ResolveFile maps a printed path onto a regular file on this machine.
It tries the selected root first, then an absolute or ~/ path. The file must exist, be regular, and survive EvalSymlinks. It does not have to sit inside the selected worktree. Display is a root-relative slash path when the file is inside base, otherwise the resolved absolute path.
func SafeHTTPURL ¶
SafeHTTPURL trims trailing prose punctuation and accepts only http(s) URLs with a host and no control characters.
Types ¶
type DiffResolver ¶ added in v1.0.0
DiffResolver reports whether a git-spec token exists in the selected checkout. Extra.Raw is the matched token; Extra.Line is unused. ok=false drops the span. A nil DiffResolver emits no git-spec spans.
type Extra ¶
Extra holds kind-specific fields. Line is 1-based and zero when the token has no :line suffix. Raw is the original file or git-spec token when Value is rewritten by a Resolver.
func ResolveGitSpec ¶ added in v1.0.0
ResolveGitSpec existence-gates a scanner token: a lowercase hex rev, "commit <rev>", or A..B / A...B. HEAD and branch names are refused here even if git would accept them — those are CLI-only.
type Resolver ¶
Resolver reports whether a file token exists. value is what the host should store (typically a path relative to the selected root). ok=false drops the span. A nil Resolver skips existence-gated file spans (bare paths).
type Span ¶
Span is one non-overlapping match in visual columns of the stripped line. EndCol is inclusive.
func Scan ¶
func Scan(line string, resolve Resolver, resolveDiff DiffResolver) []Span
Scan finds URL, file, issue, and git-spec spans in a terminal line.
line may still contain ANSI; it is stripped before matching. Overlaps are resolved first-kind-wins in this order: url, path:line, resolved bare files, issue, git spec. File tokens need a suffix. Bare files (and, when a Resolver is supplied, path:line) are existence-gated. Git specs are existence-gated by resolveDiff and scanned dotted → commit-word → rev.