views

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugLogPath added in v2.3.0

func DebugLogPath() string

DebugLogPath is where weft writes its debug and sync-failure log. Anchored to the user cache dir so a weft launched from inside the graph can't deposit weft.log where the next sync's `git add -A` would commit it into the notes repo. Falls back to the process cwd only when the cache dir is unavailable.

func RenderCount

func RenderCount() int64

RenderCount returns the current value of the per-page render counter. Used by tests.

Types

type App

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

func New

func New(graphPath, version string) *App

New returns an App that has not yet built its index. The index is built asynchronously in Init so the first frame can render a "loading" splash instead of freezing the terminal while a large graph is walked.

func (*App) Init

func (a *App) Init() tea.Cmd

func (*App) Update

func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*App) View

func (a *App) View() string
type Backlinks struct {
	// contains filtered or unexported fields
}
func NewBacklinks(idx *graph.Index, target string, unlinked []graph.UnlinkedRef, width, height int) *Backlinks

NewBacklinks builds the overlay for `target`, combining the in-memory linked backlinks with the supplied unlinked references (the App computes those via ripgrep on panel-open). Self-references are filtered from the linked list.

func (*Backlinks) SetLinkifyError

func (b *Backlinks) SetLinkifyError(msg string)

SetLinkifyError records a failure to show in the panel and drops the confirm sub-state, so the user returns to the list rather than being stuck confirming a mention that is gone. Errors must render inside the overlay — a status-bar hint would be invisible behind it.

func (*Backlinks) SetSize

func (b *Backlinks) SetSize(w, h int)

SetSize updates the cached terminal dimensions.

func (*Backlinks) Update

func (b *Backlinks) Update(key string) OverlayResult

func (*Backlinks) View

func (b *Backlinks) View() string

type EditorResult

type EditorResult struct {
	Save bool // App writes Content() to path
	Exit bool // App tears down the editor and returns to the read view
}

EditorResult is what EditorView.Update reports to the App.

type EditorView

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

EditorView is weft's in-app raw-markdown editor: a full-screen mode (not a centered overlay) that wraps bubbles/textarea. It owns the edit/save/exit state machine; the App performs the actual disk write so internal/edit stays the only writer.

func NewEditorView

func NewEditorView(idx *graph.Index, name, path, content string, isNew bool, width, height int) *EditorView

NewEditorView builds an editor for page `name` targeting `path`, primed with `content` (empty for a not-yet-created page). isNew records whether the file existed at open time. idx is the graph index used for link completion; pass nil to disable completion (e.g. in tests that don't exercise it).

func (*EditorView) Content

func (e *EditorView) Content() string

Content is the buffer normalized to end in exactly one newline.

func (*EditorView) Focus

func (e *EditorView) Focus() tea.Cmd

Focus focuses the textarea and returns its (cursor-blink) command.

func (*EditorView) MarkSaved

func (e *EditorView) MarkSaved(content string)

MarkSaved records a successful save: the given content becomes the new clean baseline and the file now exists.

func (*EditorView) SetError

func (e *EditorView) SetError(msg string)

SetError records a message (e.g. a failed save) to show in the status line until the next successful save. Surfacing it here is load-bearing: while the editor is open, App.View renders EditorView.View(), not the app status bar, so a save error routed through the app hint is invisible.

func (*EditorView) SetSize

func (e *EditorView) SetSize(w, h int)

SetSize resizes the textarea, reserving rows for the status line and the active completion strip.

func (*EditorView) Update

func (e *EditorView) Update(msg tea.KeyMsg) (EditorResult, tea.Cmd)

Update handles one key and reports whether the App should save/exit. In editing mode every key except the intercepts (ctrl+s, esc/ctrl+c, pgup/pgdown) is forwarded to the textarea. The returned tea.Cmd is the textarea's own (cursor blink) command, which the App must propagate.

func (*EditorView) View

func (e *EditorView) View() string

type Help

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

Help is a stateless overlay listing the keymap. ? or esc toggles it off.

func NewHelp

func NewHelp(version string, width, height int) *Help

NewHelp builds the help overlay at the current terminal size. width clamps rendered lines and decides single- vs two-column layout; height caps the panel so it can never overflow the screen — body lines past the cap are dropped with a faint "resize" hint, while the title and close hint always stay visible. Passing width or height as 0 disables that dimension's constraint, yielding the natural content-sized panel (used by tests).

func (*Help) SetSize

func (h *Help) SetSize(w, ht int)

SetSize updates the cached terminal size.

func (*Help) Update

func (h *Help) Update(key string) OverlayResult

Update reports whether the overlay should close. There's no state to mutate.

func (*Help) View

func (h *Help) View() string

type Overlay

type Overlay interface {
	Update(key string) OverlayResult
	View() string
	SetSize(w, h int)
}

Overlay is a modal view layered over the page. App routes keys to the active overlay and closes it when Update reports Accept or Cancel.

type OverlayResult

type OverlayResult struct {
	// Selected is the page to open when Accept is true. Empty means "accept
	// but navigate nowhere" (e.g. a search hit whose file isn't indexed).
	Selected string
	// TaskOrdinal is the 0-based open-todo index on the selected page to
	// scroll to, honoured only when DeepLink is true. Only the Todos overlay
	// sets these; other overlays leave DeepLink false and the page opens at
	// the top.
	TaskOrdinal int
	DeepLink    bool
	Accept      bool // user chose Selected; App navigates (if non-empty) and closes
	Cancel      bool // user dismissed; App closes the overlay
	// Create, when Accept is true, means "create the page named Selected"
	// rather than open an existing one. Only the Picker sets it.
	Create bool
	// FocusLinkTo, when Accept is true and non-empty, asks the App to position
	// the destination page's link cursor on the first link back to this page
	// (so a backlink jump lands on — and highlights — the referencing link).
	// Only the Backlinks overlay sets it, and only for linked refs.
	FocusLinkTo string
	// HighlightText, when Accept is true and non-empty, asks the App to navigate
	// to Selected and highlight occurrences of this term on the destination
	// (scrolling to the first). Only the Backlinks overlay sets it, for unlinked
	// refs.
	HighlightText string
	// Linkify, when non-nil, asks the App to wrap LinkifyTarget as a [[link]]
	// at this unlinked reference's location in its source file, then reindex
	// and refresh the panel. Only the Backlinks overlay sets it.
	Linkify *graph.UnlinkedRef
	// LinkifyTarget is the page name to wrap, honoured only when Linkify is set.
	LinkifyTarget string
	Cmd           tea.Cmd // optional async work to run (search launches rg here)
}

OverlayResult is what an overlay's Update reports back to the App.

type PageView

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

PageView renders a single page with a wiki-link cursor.

func NewPageView

func NewPageView(idx *graph.Index, page string, width, height int) *PageView

func (*PageView) Cursor

func (p *PageView) Cursor() int

Cursor returns the current link cursor index. -1 means no link selected.

func (p *PageView) CycleLink(dir int)

CycleLink moves the cursor to the next/previous wiki-link, scrolling the viewport so the new cursor target is visible. dir=+1 forwards, dir=-1 backwards.

func (*PageView) FocusLinkTo

func (p *PageView) FocusLinkTo(name string)

FocusLinkTo positions the link cursor on the first link whose target resolves to name and scrolls it into view. No-op when the page has no such link.

func (*PageView) FollowCursor

func (p *PageView) FollowCursor() string

FollowCursor returns the link target under the cursor, or "" if none.

func (*PageView) GotoBottom

func (p *PageView) GotoBottom()

func (*PageView) GotoTop

func (p *PageView) GotoTop()

func (*PageView) HalfPageDown

func (p *PageView) HalfPageDown()

func (*PageView) HalfPageUp

func (p *PageView) HalfPageUp()

func (*PageView) LineDown

func (p *PageView) LineDown()

LineDown/LineUp/HalfPage/Goto delegates to viewport.

func (*PageView) LineUp

func (p *PageView) LineUp()

func (*PageView) Offset

func (p *PageView) Offset() int

Offset returns the viewport's current scroll position (YOffset).

func (*PageView) Page

func (p *PageView) Page() string

Page returns the currently displayed page name.

func (*PageView) Restore

func (p *PageView) Restore(offset, cursor int)

Restore sets the viewport scroll offset and link cursor in one shot. The viewport's SetYOffset clamps offset against the current content height. Cursor is clamped to a valid link index; anything outside [0, len(Links)) falls back to -1 (no link selected). Use after SetPage to recover scroll/cursor state captured before a navigation.

func (*PageView) ScrollIndicator

func (p *PageView) ScrollIndicator() string

ScrollIndicator returns "" when the page fits the viewport (no scroll possible), otherwise "NN%" — 0% at the top, 100% at the bottom. viewport.ScrollPercent is already clamped to [0, 1] and returns exactly 0 at YOffset=0 and 1 at the max offset.

func (*PageView) ScrollToTask

func (p *PageView) ScrollToTask(ordinal int)

ScrollToTask centres the viewport on the open todo at the given 0-based ordinal (its position among the page's open todos in document order, as recorded in render.Result.Tasks). No-op when the ordinal is out of range. One-shot deep-link jump applied at SetPage time — not a property Restore rewinds into.

func (*PageView) SetPage

func (p *PageView) SetPage(name string)

SetPage switches to a different page in the same index. The viewport starts at the top — a fresh navigation must not inherit the previous page's scroll position (history Restore sets an explicit offset after this when walking [ / ]).

func (*PageView) SetPageEmphasizing

func (p *PageView) SetPageEmphasizing(name, term string)

SetPageEmphasizing switches to name and highlights whole-word occurrences of term (the page navigated from), scrolling to the first. The highlight is transient: a later SetPage or history Restore clears it.

func (*PageView) SetSize

func (p *PageView) SetSize(w, h int)

SetSize updates viewport size. The page body is only re-rendered when the width changes — height changes don't affect word-wrap, so we just resize the viewport and let it re-clip the existing styled content.

func (*PageView) StatusLine

func (p *PageView) StatusLine() string

StatusLine returns the text to display on the left side of the App-level status bar: page name, plus a link count or cursor position when relevant.

func (*PageView) View

func (p *PageView) View() string

type Picker

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

func NewPicker

func NewPicker(idx *graph.Index, width, height int) *Picker

func (*Picker) SetSize

func (b *Picker) SetSize(w, h int)

SetSize updates the cached terminal dimensions.

func (*Picker) Update

func (p *Picker) Update(key string) OverlayResult

Update handles a key and reports the result to the App.

func (*Picker) View

func (p *Picker) View() string

type SearchView

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

func NewSearchView

func NewSearchView(idx *graph.Index, width, height int) *SearchView

func (*SearchView) Apply

func (s *SearchView) Apply(msg searchDoneMsg)

Apply installs a finished search's results. Results from an edited-away query (stale gen) are dropped. A failed search leaves searched=false so enter retries instead of dead-ending the query.

func (*SearchView) Query

func (s *SearchView) Query() string

func (*SearchView) SearchCmd

func (s *SearchView) SearchCmd(graphPath string) tea.Cmd

SearchCmd returns a tea.Cmd that runs rg and returns a searchDoneMsg tagged with this view instance and the query's generation at launch time, so a result for an edited-away query (or a since-replaced overlay) can be dropped instead of landing under whatever query is current now.

func (*SearchView) SetQuery

func (s *SearchView) SetQuery(q string)

SetQuery sets the query directly; test-only — it does not bump gen, so production code must mutate the query through Update to keep the staleness guard correct.

func (*SearchView) SetSize

func (b *SearchView) SetSize(w, h int)

SetSize updates the cached terminal dimensions.

func (*SearchView) Update

func (s *SearchView) Update(key string) OverlayResult

Update handles a key and reports the result to the App.

func (*SearchView) View

func (s *SearchView) View() string

type Todos

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

func NewTodos

func NewTodos(idx *graph.Index, width, height int) *Todos

func (*Todos) SetSize

func (b *Todos) SetSize(w, h int)

SetSize updates the cached terminal dimensions.

func (*Todos) Update

func (t *Todos) Update(key string) OverlayResult

func (*Todos) View

func (t *Todos) View() string

Jump to

Keyboard shortcuts

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