docview

package
v0.99.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 20 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 = 8

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

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
}

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

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

HandleKey applies document scrolling keys.

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

func (m *Model) ScrollOffset() int

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

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) 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) 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 struct {
	Index    int
	Col      int
	Width    int
	Rendered string
}

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 struct {
	Row  string
	Tabs []TabHit
}

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

func LayoutTabStrip added in v0.99.1

func LayoutTabStrip(tabs 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) 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