docview

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 25 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 docview is the shared file viewer: one document, wrap, and path actions (info, reveal, yank). Hosts own tabs and chrome.

Index

Constants

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

func FetchGitInfo(root, path string) tea.Cmd

FetchGitInfo retrieves git status and last commit for a root-relative path.

func FormatSize added in v0.99.0

func FormatSize(bytes int64) string

FormatSize formats a byte count in human-readable form.

func NormalizeTabPath added in v0.99.0

func NormalizeTabPath(path string) string

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 Reveal added in v0.99.0

func Reveal(root, path string) tea.Cmd

Reveal opens path in the OS file manager. path is root-relative.

func VisibleTabRange added in v0.99.0

func VisibleTabRange(widths []int, active, maxWidth int) (start, end int, showLeft, showRight bool)

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

func YankContents(root, path string) tea.Cmd

YankContents copies the file at root/path to the clipboard.

func YankPath added in v0.99.0

func YankPath(path string) tea.Cmd

YankPath copies the relative 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

type GitInfoMsg struct {
	Path       string
	Status     string
	LastCommit string
}

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

func NewGutter(lineCount int) Gutter

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

func NewGutterForWidth(lineCount, totalWidth int) Gutter

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

func (g Gutter) Blank() string

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) Enabled added in v1.0.0

func (g Gutter) Enabled() bool

Enabled reports whether this gutter renders anything.

func (Gutter) Number added in v1.0.0

func (g Gutter) Number(line int) string

Number renders the cell for a 1-based source line number.

func (Gutter) Plain added in v1.0.0

func (g Gutter) Plain(line int) string

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

func (g Gutter) Width() int

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

func (g Gutter) WithSeparator(sep string) Gutter

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 OpenInfo added in v0.99.0

func OpenInfo(root, path string) (*Info, tea.Cmd)

OpenInfo starts the info modal and fetches git details.

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

func (i *Info) HandleKey(msg tea.KeyPressMsg) (closed bool, cmd tea.Cmd)

HandleKey routes modal keys. closed is true when the user dismissed it.

func (*Info) HandleMouse added in v0.99.0

func (i *Info) HandleMouse(msg tea.MouseMsg, handler *mouse.Handler) (closed bool)

HandleMouse routes modal mouse events. closed is true on dismiss.

func (*Info) Render added in v0.99.0

func (i *Info) Render(width, height int, handler *mouse.Handler) string

Render paints the modal and registers its hit regions.

func (*Info) WheelAtBoundary added in v1.0.0

func (i *Info) WheelAtBoundary(msg tea.MouseWheelMsg, handler *mouse.Handler) bool

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 Item added in v0.99.0

type Item struct {
	View *Model
}

Item is one open document.

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.

func (LoadedMsg) GetEpoch

func (m LoadedMsg) GetEpoch() uint64

GetEpoch allows callers to apply the normal plugin epoch checks if desired.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is one markdown document in one content box.

func New

func New(renderer *markdown.Renderer) *Model

New creates an empty document viewer. A nil renderer uses the default markdown renderer.

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

func (m *Model) ApplyLine(line int)

ApplyLine jumps to line (1-based) and forces raw mode so the line is visible.

func (*Model) Arm added in v0.99.0

func (m *Model) Arm(modelID int, relPath string, epoch uint64)

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

func (m *Model) HandleKey(k tea.KeyMsg) bool

HandleKey applies document scrolling keys.

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

func (m *Model) HasSelection() bool

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

func (m *Model) Load(modelID int, rootDir, relPath string, line int, epoch uint64) tea.Cmd

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

func (m *Model) NeedsLoad() bool

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

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

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

func (m *Model) RefreshPending() bool

RefreshPending reports whether a re-read is owed but has not started.

func (*Model) Rendered

func (m *Model) Rendered() bool

Rendered reports whether markdown is shown rendered rather than raw.

func (*Model) Scroll

func (m *Model) Scroll(delta int)

Scroll moves the viewport by delta rows and clamps it to the document.

func (*Model) ScrollAtBoundary added in v1.0.0

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

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

func (m *Model) ScrollOffset() int

ScrollOffset is the current (or still-pending restore) viewport offset.

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

func (m *Model) SelectionText() []string

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

func (m *Model) SetOrigin(x, y int)

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

func (m *Model) SetPendingScroll(offset int)

SetPendingScroll remembers an offset to apply after the next successful load.

func (*Model) SetRendered

func (m *Model) SetRendered(rendered bool)

SetRendered restores the persisted display mode.

func (*Model) SetResult

func (m *Model) SetResult(msg LoadedMsg) bool

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

func (m *Model) SetRoot(root string)

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

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

SetSize sets the content box dimensions. A width change invalidates rendered markdown because wrapping depends on it.

func (*Model) SetWrap added in v0.99.0

func (m *Model) SetWrap(wrap bool)

SetWrap restores the persisted wrap flag.

func (*Model) Title

func (m *Model) Title() string

Title returns the document's relative path.

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

func (m *Model) View() string

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

func (m *Model) WatchTarget() livewatch.Target

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.

func (*Model) Wrap added in v0.99.0

func (m *Model) Wrap() bool

Wrap reports whether long lines wrap instead of truncating.

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

type TabHit = tabs.Hit

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

type TabStrip = tabs.Strip

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

func LayoutTabStrip added in v0.99.1

func LayoutTabStrip(group Tabs, width int, focused bool) TabStrip

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

type Tabs struct {
	Items  []Item
	Active int
}

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

func (t Tabs) ActiveView() *Model

ActiveView is the selected document, or nil.

func (*Tabs) Append added in v0.99.0

func (t *Tabs) Append(view *Model)

Append adds view and selects it.

func (Tabs) ClearSelectionsExcept added in v1.1.0

func (t Tabs) ClearSelectionsExcept(keep *Model)

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

func (t *Tabs) Cycle(delta int)

Cycle moves Active by delta, wrapping at the ends. A single tab is a no-op.

func (Tabs) IndexOf added in v0.99.0

func (t Tabs) IndexOf(path string) int

IndexOf returns the tab whose display path matches path, or -1. The key is the root-relative path, slash-normalized.

func (*Tabs) Select added in v0.99.0

func (t *Tabs) Select(i int)

Select makes i the active tab.

func (Tabs) VisibleRange added in v0.99.0

func (t Tabs) VisibleRange(widths []int, maxWidth int) (start, end int, showLeft, showRight bool)

VisibleRange is the overflow window for this group: the inclusive [start, end] of tabs that fit in maxWidth, keeping Active on screen.

Jump to

Keyboard shortcuts

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