Documentation
¶
Overview ¶
Package docview is the shared file viewer: one document, wrap, and path actions (info, reveal, yank). Hosts own tabs and chrome.
Index ¶
- Constants
- func FetchGitInfo(root, path string) tea.Cmd
- func FormatSize(bytes int64) string
- func InjectHighlights(row string, ranges []MatchRange, current int) string
- func NormalizeTabPath(path string) string
- func RenderInfo(d FileDetails, gitStatus, lastCommit string) string
- func Reveal(root, path string) tea.Cmd
- func SearchCommands(context string) []plugin.Command
- func VisibleTabRange(widths []int, active, maxWidth int) (start, end int, showLeft, showRight bool)
- func YankContents(root, path string) tea.Cmd
- func YankPath(path string) tea.Cmd
- type FileDetails
- type GitInfoMsg
- type Gutter
- type Info
- func (i *Info) ApplyGit(msg GitInfoMsg)
- func (i *Info) HandleKey(msg tea.KeyPressMsg) (closed bool, cmd tea.Cmd)
- func (i *Info) HandleMouse(msg tea.MouseMsg, handler *mouse.Handler) (closed bool)
- func (i *Info) Render(width, height int, handler *mouse.Handler) string
- func (i *Info) WheelAtBoundary(msg tea.MouseWheelMsg, handler *mouse.Handler) bool
- type Item
- type LoadedMsg
- type Match
- type MatchRange
- type Model
- func (m *Model) AbandonSelection() textselect.Result
- func (m *Model) ApplyLine(line int)
- func (m *Model) Arm(modelID int, relPath string, epoch uint64)
- func (m *Model) ClearSelection()
- func (m *Model) CloseSearch()
- func (m *Model) HandleKey(k tea.KeyMsg) bool
- func (m *Model) HandleSearchKey(msg tea.KeyMsg) (bool, tea.Cmd)
- func (m *Model) HandleSelectionKey(msg tea.KeyMsg) textselect.Result
- func (m *Model) HandleSelectionMouse(action mouse.MouseAction) textselect.Result
- func (m *Model) HasSelection() bool
- func (m *Model) Load(modelID int, rootDir, relPath string, line int, epoch uint64) tea.Cmd
- func (m *Model) LoadFile(modelID int, file *os.File, relPath string, line int, epoch uint64) tea.Cmd
- func (m *Model) NeedsLoad() bool
- func (m *Model) Observe()
- func (m *Model) Refresh(suppressed bool) tea.Cmd
- func (m *Model) RefreshPending() bool
- func (m *Model) Rendered() bool
- func (m *Model) Root() string
- func (m *Model) Scroll(delta int)
- func (m *Model) ScrollAtBoundary(delta int) bool
- func (m *Model) ScrollOffset() int
- func (m *Model) SearchActive() bool
- func (m *Model) SearchCommitted() bool
- func (m *Model) SearchMatchIndex() int
- func (m *Model) SearchMatches() []Match
- func (m *Model) SearchQuery() string
- func (m *Model) SelectionCopyCmd(result textselect.Result, wrap func(textselect.CopyNotice) tea.Msg) tea.Cmd
- func (m *Model) SelectionText() []string
- func (m *Model) SetOrigin(x, y int)
- func (m *Model) SetPendingScroll(offset int)
- func (m *Model) SetRendered(rendered bool)
- func (m *Model) SetResult(msg LoadedMsg) bool
- func (m *Model) SetRoot(root string)
- func (m *Model) SetSelection(keys textselect.Keys, copyOnSelect bool)
- func (m *Model) SetSize(width, height int)
- func (m *Model) SetWrap(wrap bool)
- func (m *Model) StartSearch()
- func (m *Model) Title() string
- func (m *Model) ToggleRenderMode()
- func (m *Model) ToggleWrap()
- func (m *Model) TopSourceLine() int
- func (m *Model) View() string
- func (m *Model) WatchTarget() livewatch.Target
- func (m *Model) Wrap() bool
- type RevealErrorMsg
- type TabHit
- type TabStrip
- type Tabs
- func (t Tabs) ActiveView() *Model
- func (t *Tabs) Append(view *Model)
- func (t Tabs) ClearSelectionsExcept(keep *Model)
- func (t *Tabs) CloseActive()
- func (t *Tabs) Cycle(delta int)
- func (t Tabs) IndexOf(path string) int
- func (t *Tabs) Select(i int)
- func (t Tabs) VisibleRange(widths []int, maxWidth int) (start, end int, showLeft, showRight bool)
Constants ¶
const TabMinBudget = tabs.MinBudget
TabMinBudget is the floor for one tab's column share, chrome included.
Variables ¶
This section is empty.
Functions ¶
func FetchGitInfo ¶ added in v0.99.0
FetchGitInfo retrieves git status and last commit for a root-relative path.
func FormatSize ¶ added in v0.99.0
FormatSize formats a byte count in human-readable form.
func InjectHighlights ¶ added in v1.2.0
func InjectHighlights(row string, ranges []MatchRange, current int) string
InjectHighlights walks an ANSI-styled row and opens/closes highlight sequences at the given plain-text byte offsets, leaving the row's own styling in place. Ranges must be sorted by Start; current is the index of the match that gets the "current match" styling.
func NormalizeTabPath ¶ added in v0.99.0
NormalizeTabPath is the dedup key: slash-normalized, cleaned display path.
func RenderInfo ¶ added in v0.99.0
func RenderInfo(d FileDetails, gitStatus, lastCommit string) string
RenderInfo paints the file-info field list.
func SearchCommands ¶ added in v1.2.0
SearchCommands is the footer vocabulary of a live in-file search, in one place so the project workspace and the global Workspaces browser cannot advertise different keys for the same bar. The caller supplies its own focus context; the IDs are what internal/keymap registers the bindings under, and they are the Files plugin's own so one feature has one vocabulary everywhere.
func VisibleTabRange ¶ added in v0.99.0
VisibleTabRange is the inclusive [start, end] window of tabs that fit in maxWidth given their rendered widths, keeping the active tab visible. showLeft and showRight are the overflow markers for tabs outside the window.
func YankContents ¶ added in v0.99.0
YankContents copies the file at root/path to the clipboard.
Types ¶
type FileDetails ¶ added in v0.99.0
type FileDetails struct {
Path string
Name string
Kind string
Size string
Where string
Modified string
Permissions string
IsDir bool
Err error
}
FileDetails is stat + classification for a root-relative path.
func Inspect ¶ added in v0.99.0
func Inspect(root, path string) FileDetails
Inspect stats a root-relative path.
type GitInfoMsg ¶ added in v0.99.0
GitInfoMsg is git status and last commit for a path.
type Gutter ¶ added in v1.0.0
type Gutter struct {
// contains filtered or unexported fields
}
Gutter renders the line-number column beside a document's text. It is a value type with no state beyond its width, so callers can build one per render pass.
The zero Gutter is disabled: it has zero width and renders empty cells, so a caller that suppresses numbering (rendered markdown, placeholder text) can keep one code path.
func NewGutter ¶ added in v1.0.0
NewGutter returns a gutter wide enough to number a document of lineCount lines, never narrower than the historical four digits.
func NewGutterForWidth ¶ added in v1.0.0
NewGutterForWidth is NewGutter plus the "is there room?" decision: it returns a disabled gutter when numbering would leave less than minGutterContentWidth cells for the text itself.
func (Gutter) Blank ¶ added in v1.0.0
Blank renders an equal-width empty cell, for wrapped continuation rows and for lines that have no source line number of their own.
func (Gutter) Plain ¶ added in v1.0.0
Plain renders the cell for a 1-based source line number without styling, for callers that need the text to do their own column arithmetic on.
func (Gutter) Width ¶ added in v1.0.0
Width is the cell width of every cell this gutter renders, including the separator. It is 0 when the gutter is disabled.
func (Gutter) WithSeparator ¶ added in v1.0.0
WithSeparator returns a copy of g whose numbers are followed by sep instead of a single space, for callers that punctuate the column (" 12: text"). The separator counts towards Width, so a caller that budgets by Width never has to know which one it got.
type Info ¶ added in v0.99.0
type Info struct {
Root, Path string
GitStatus, LastCommit string
// contains filtered or unexported fields
}
Info is a file-info modal for a (root, path).
func (*Info) ApplyGit ¶ added in v0.99.0
func (i *Info) ApplyGit(msg GitInfoMsg)
ApplyGit records a fetch that belongs to this path.
func (*Info) HandleKey ¶ added in v0.99.0
HandleKey routes modal keys. closed is true when the user dismissed it.
func (*Info) HandleMouse ¶ added in v0.99.0
HandleMouse routes modal mouse events. closed is true on dismiss.
func (*Info) WheelAtBoundary ¶ added in v1.0.0
WheelAtBoundary reports whether this wheel event is certainly a no-op for the info modal, using the geometry of its most recent render. It never rebuilds or mutates content, and reports unknown (false) before the first render.
type LoadedMsg ¶
type LoadedMsg struct {
ModelID int
RequestGeneration uint64
Epoch uint64
Path string
Result filepreview.PreviewResult
// Refresh marks a result produced by Model.Refresh rather than Model.Load:
// an in-place re-read that preserves scroll and is discarded when the file
// came back unchanged. See live.go.
Refresh bool
}
LoadedMsg is the result of a Model load. Its identity fields ensure a result can only be applied to the model, request, and plugin epoch that issued it.
type Match ¶ added in v1.2.0
Match is one hit, in the coordinate space described above: Line indexes the content lines of the current layout (banner rows included, because they are on screen and searchable), and Start/End are byte offsets into that line's joined plain text.
type MatchRange ¶ added in v1.2.0
type MatchRange struct {
Index int // position in the match list, so the current match can be told apart
Start int
End int
}
MatchRange is a highlight to inject, in plain-text byte offsets into one row. It is exported because hosts whose renderer is not a docview.Model — the files plugin's preview pane — paint their own rows through InjectHighlights rather than carrying a second copy of this logic.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is one markdown document in one content box.
func (*Model) AbandonSelection ¶ added in v1.1.0
func (m *Model) AbandonSelection() textselect.Result
AbandonSelection ends a gesture whose release never arrived — the pointer left the window, a modal opened, focus moved.
func (*Model) ApplyLine ¶ added in v0.99.0
ApplyLine jumps to line (1-based) and forces raw mode so the line is visible.
func (*Model) Arm ¶ added in v0.99.0
Arm shows the loading placeholder for a restored tab without issuing a load.
func (*Model) ClearSelection ¶ added in v1.1.0
func (m *Model) ClearSelection()
ClearSelection drops the selection and any gesture editing it.
func (*Model) CloseSearch ¶ added in v1.2.0
func (m *Model) CloseSearch()
CloseSearch ends the search and drops its matches.
func (*Model) HandleSearchKey ¶ added in v1.2.0
HandleSearchKey answers a key while search owns the pane. It reports whether the key was consumed; a live search consumes every key it is offered, which is what makes esc the only way out and stops a query containing "n" from scrolling the document.
The returned command exists for hosts to batch: search itself has no side effects outside the model today.
func (*Model) HandleSelectionKey ¶ added in v1.1.0
func (m *Model) HandleSelectionKey(msg tea.KeyMsg) textselect.Result
HandleSelectionKey answers the chords that act on the selection: copy, select-all, and escape.
Escape belongs here rather than in each host: what it means to a live selection is the selection's business, and a host that wrote the rule itself would be a host the other surface has to remember to match.
func (*Model) HandleSelectionMouse ¶ added in v1.1.0
func (m *Model) HandleSelectionMouse(action mouse.MouseAction) textselect.Result
HandleSelectionMouse advances the selection gesture and reports what the host owes for it.
A drag that has run past an edge is scrolled here rather than by the host: the window it is asking for is this model's own, and a host that moved it would be the second place that knows how far a document can scroll. The rows it reveals are selected by the next motion event, as the engine's contract says. AutoScroll is reported back as the rows that were actually applied — a document already at its last row moves nothing — so a host that persists the offset saves exactly when a drag changed it.
func (*Model) HasSelection ¶ added in v1.1.0
HasSelection reports whether anything in this document is selected. It is asked by hosts outside a render — a key, a click elsewhere — so it settles the expiry itself rather than reporting a selection the next frame will drop.
func (*Model) Load ¶
Load retargets the model and returns a command that wraps the existing file browser loader. Only the docview-owned LoadedMsg is broadcast.
func (*Model) LoadFile ¶
func (m *Model) LoadFile(modelID int, file *os.File, relPath string, line int, epoch uint64) tea.Cmd
LoadFile retargets the model from an already-open file. The returned command owns and closes file after reading it.
func (*Model) NeedsLoad ¶ added in v0.99.0
NeedsLoad reports whether this model has never been asked to Load.
func (*Model) Observe ¶ added in v1.0.0
func (m *Model) Observe()
Observe records that the document's file changed on disk.
A document that has never loaded declines to be owed a re-read: the host's own load path owns it, Model.Refresh refuses before it reaches the refresher, and a dirty flag nothing can clear reads to a host as a refresh owed forever.
func (*Model) Refresh ¶ added in v1.0.0
Refresh returns a command that re-reads the document in place, or nil when no re-read is owed.
Unlike Model.Load it preserves the scroll offset, the render mode and the wrap setting, and it leaves the current text on screen while the re-read runs rather than flashing a loading placeholder.
suppressed is the host's veto. A vetoed refresh stays owed and lands as soon as the veto lifts, so a host may safely block refreshes while something else owns the pane without losing the update.
func (*Model) RefreshPending ¶ added in v1.0.0
RefreshPending reports whether a re-read is owed but has not started.
func (*Model) Root ¶ added in v1.2.0
Root reports the directory the relative path is resolved against. It is what a host needs to hand the file to something outside docview — an editor, a reveal, a yank — without keeping a second copy of the pane's root.
func (*Model) ScrollAtBoundary ¶ added in v1.0.0
ScrollAtBoundary reports whether delta would leave this document's current viewport unchanged. It is safe to ask before Update/View.
func (*Model) ScrollOffset ¶ added in v0.99.0
ScrollOffset is the current (or still-pending restore) viewport offset.
func (*Model) SearchActive ¶ added in v1.2.0
SearchActive reports whether the search bar is on screen and owns the pane's keys. A host asks this to decide whether a keypress is search's before it is anyone else's.
func (*Model) SearchCommitted ¶ added in v1.2.0
SearchCommitted reports whether the query has been committed with enter, so n/N navigate rather than typing into the query.
func (*Model) SearchMatchIndex ¶ added in v1.2.0
SearchMatchIndex is the 0-based cursor into SearchMatches.
func (*Model) SearchMatches ¶ added in v1.2.0
SearchMatches is the current match set, recomputed first if the document or its layout moved underneath it.
func (*Model) SearchQuery ¶ added in v1.2.0
SearchQuery is the query as typed.
func (*Model) SelectionCopyCmd ¶ added in v1.1.0
func (m *Model) SelectionCopyCmd(result textselect.Result, wrap func(textselect.CopyNotice) tea.Msg) tea.Cmd
SelectionCopyCmd delivers the copy an engine result asked for, phrased by the shared pipeline and wrapped in whatever notification type the host uses. A result that asked for nothing produces no command, so a host can hand every result it gets straight here.
func (*Model) SelectionText ¶ added in v1.1.0
SelectionText is the selection as the user sees it: the visible rows, without the styling they were drawn with and without the gutter in front of them.
func (*Model) SetOrigin ¶ added in v1.1.0
SetOrigin records where the host last drew this document's content box, in the coordinate space its mouse events arrive in. A pane that has not been drawn has no origin, so it hit-tests as empty rather than as the top-left corner of the screen.
func (*Model) SetPendingScroll ¶ added in v0.99.0
SetPendingScroll remembers an offset to apply after the next successful load.
func (*Model) SetRendered ¶
SetRendered restores the persisted display mode.
func (*Model) SetResult ¶
SetResult applies msg if it belongs to the current load. It returns false without changing the model for stale model, request, epoch, or path results.
func (*Model) SetRoot ¶ added in v1.0.0
SetRoot records the directory that m.path is relative to.
Model.Load takes it as an argument, but Model.LoadFile is handed an already-open file and never learns where it came from. A host that loads by file descriptor must call this, or the pane cannot be refreshed — it has no path to re-read.
func (*Model) SetSelection ¶ added in v1.1.0
func (m *Model) SetSelection(keys textselect.Keys, copyOnSelect bool)
SetSelection binds the host's shared selection settings: the chords the pane answers, and whether finishing a drag copies without being asked.
func (*Model) SetSize ¶
SetSize sets the content box dimensions. A width change invalidates rendered markdown because wrapping depends on it.
func (*Model) StartSearch ¶ added in v1.2.0
func (m *Model) StartSearch()
StartSearch opens the search bar in its typing phase with an empty query.
func (*Model) ToggleRenderMode ¶
func (m *Model) ToggleRenderMode()
ToggleRenderMode switches between rendered markdown and raw highlighted source. Each mode keeps the current offset where possible.
func (*Model) ToggleWrap ¶ added in v0.99.0
func (m *Model) ToggleWrap()
ToggleWrap flips line wrapping.
func (*Model) TopSourceLine ¶ added in v1.2.0
TopSourceLine reports the 1-indexed source line at the top of the viewport, or 0 when the rows on screen do not map onto source lines (rendered markdown, a placeholder, an empty document). Hosts use it to open an editor where the reader was looking.
func (*Model) View ¶
View returns exactly the configured number of rows, each no wider than the configured width in terminal cells.
func (*Model) WatchTarget ¶ added in v1.0.0
WatchTarget returns what to watch for changes to the document this model is showing, or an empty target when the model has no resolvable path.
It is the file itself, not its directory: a document pane is open on one document, and the surrounding directory can be enormous. livewatch still registers the parent with the kernel, because atomic writers replace a file rather than writing through it, but only events naming this exact path are reported.
type RevealErrorMsg ¶ added in v0.99.0
type RevealErrorMsg struct {
Err error
}
RevealErrorMsg is sent when reveal in the OS file manager fails.
type TabHit ¶ added in v0.99.1
TabHit is a drawn tab's click target. Col is relative to the strip's first column; Width is the rendered pill.
type TabStrip ¶ added in v0.99.1
TabStrip is the header row: only tabs, packed left to right.
func LayoutSearchTabStrip ¶ added in v1.2.0
LayoutSearchTabStrip is the same strip with the active tab renamed to a live search surface and its query, so a pane taking search keystrokes never reads as a pane showing a file. A pane opened straight into the finder has no tabs yet, and the label is the whole strip.
It lives here rather than in a host because both pane surfaces draw the same strip for the same surfaces.
func LayoutTabStrip ¶ added in v0.99.1
LayoutTabStrip is the document header: a left-truncated path tab strip and nothing else. Overflow lives on the tab group. Hosts draw this row and register hit regions from the same Tabs so a click cannot land on a tab that was never rendered.
type Tabs ¶ added in v0.99.0
Tabs is a document pane's open files. The pane tree points at this group, not at one model.
func (Tabs) ActiveView ¶ added in v0.99.0
ActiveView is the selected document, or nil.
func (Tabs) ClearSelectionsExcept ¶ added in v1.1.0
ClearSelectionsExcept drops every selection in this group but keep's, which is what makes one selection at a time the rule: starting one anywhere drops the one before it. A nil keep drops them all.
func (*Tabs) CloseActive ¶ added in v0.99.0
func (t *Tabs) CloseActive()
CloseActive removes the selected tab. The next tab (or the new last) is selected. An empty group leaves Active at 0.
func (*Tabs) Cycle ¶ added in v0.99.0
Cycle moves Active by delta, wrapping at the ends. A single tab is a no-op.