Documentation
¶
Overview ¶
Package viewer is the main markdown viewer/editor TUI component.
Index ¶
- func CheckConflicts(km KeyMap, appKeys config.Keys) []string
- func KeysFromString(raw string) []string
- type Direction
- type KeyMap
- type Model
- func (v *Model) ActiveContent() string
- func (v *Model) ActiveFilePath() string
- func (v *Model) ActiveMode() common.Mode
- func (v *Model) ActivePaneIndex() int
- func (v *Model) ActiveTabDiskChanged() bool
- func (v *Model) ActiveTabHasRecovery() bool
- func (v *Model) ActiveTabIndex() int
- func (v *Model) ActiveTabSwapPath() string
- func (v *Model) ActiveTabWarning() (hasRecovery, diskChanged, modified bool, filePath string)
- func (v *Model) ClearSearch()
- func (v *Model) ClearTabs()
- func (v *Model) CloseActivePane()
- func (v *Model) CloseAllCleanTabs() bool
- func (v *Model) CloseTab()
- func (v *Model) CloseTabByPath(path string)
- func (v *Model) ConvertTabsToSpaces(tabWidth int)
- func (v *Model) EnterInsertMode()
- func (v *Model) EnterNormalMode()
- func (v *Model) ExitInsertMode()
- func (v *Model) ExitNormalMode()
- func (v *Model) ExitVisualMode()
- func (v *Model) FocusNeighbor(dir Direction) bool
- func (v *Model) GetKeyMap() KeyMap
- func (v *Model) GotoLine(lineNum int)
- func (v *Model) HasPendingInput() bool
- func (v *Model) HasSearch() bool
- func (v *Model) HasTabs() bool
- func (v *Model) HasUnsavedChanges() bool
- func (v *Model) InsertAtCursor(text string)
- func (v *Model) IsActiveModified() bool
- func (v *Model) IsEditing() bool
- func (v *Model) IsNormal() bool
- func (v *Model) IsVisual() bool
- func (v *Model) LoadFile(path string)
- func (v *Model) ModeInfo() (common.Mode, int, int)
- func (v *Model) MoveTabLeft()
- func (v *Model) MoveTabRight()
- func (v *Model) MoveTabToNeighbor(dir Direction) bool
- func (v *Model) NextTab()
- func (v *Model) PaneCount() int
- func (v *Model) PrevTab()
- func (v *Model) RecoverActiveTab(content []byte) bool
- func (v *Model) RefreshAllTabs()
- func (v *Model) ReloadActiveTab(data []byte, mtime time.Time)
- func (v *Model) SaveFile() (string, bool)
- func (v *Model) SearchMatchCount() int
- func (v *Model) SearchNext() (found, wrapped bool)
- func (v *Model) SearchPrev() (found, wrapped bool)
- func (v *Model) SearchStatus() string
- func (v *Model) SelectionInfo() string
- func (v *Model) SetActiveFilePath(path string)
- func (v *Model) SetActiveTabModified(modified bool)
- func (v *Model) SetActiveTabRecovery(hasRecovery bool)
- func (v *Model) SetCheckboxStates(states []string)
- func (v *Model) SetCustomTheme(t *theme.CustomTheme)
- func (v *Model) SetDefaultMode(m common.Mode)
- func (v *Model) SetFoldLevel(n int)
- func (v *Model) SetKeyMap(km KeyMap)
- func (v *Model) SetSearch(query string) int
- func (v *Model) SetSize(w, h int)
- func (v *Model) SetStyles(s Styles)
- func (v *Model) SetTabSpaces(s string)
- func (v *Model) SetTabWidth(n int)
- func (v *Model) SetTheme(s string)
- func (v *Model) SetupFileTracking(swapPath string, mtime time.Time)
- func (v *Model) SplitPane(direction splitDir)
- func (v *Model) SplitPaneHoriz() bool
- func (v *Model) SplitPaneVert() bool
- func (v *Model) TabCount() int
- func (v *Model) Tick(writeSwapFn func(swapPath, filePath string, content []byte) error) (changedPath string, hasConflict bool)
- func (v *Model) ToggleAllFolds(folded bool)
- func (v *Model) ToggleCheckbox()
- func (v Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (v Model) View(focused bool) string
- func (v *Model) Width() int
- type OpenLinkMsg
- type SearchMsg
- type StatusMsg
- type Styles
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckConflicts ¶
CheckConflicts inspects km for two classes of problem and returns a human-readable warning for each one found:
Intra-mode conflicts same handler group (view / normal / visual). Cross-mode reuse of the same key by different bindings (e.g. "d" for DeletePrefix in normal and Cut in visual) is intentional and is NOT flagged.
Viewer-vs-app conflicts that is intercepted before the viewer sees input.
func KeysFromString ¶
KeysFromString parses a comma-separated key string into a trimmed slice (public).
Types ¶
type KeyMap ¶
type KeyMap struct {
// Movement (shared across Normal, Visual, View modes)
MoveDown key.Binding
MoveUp key.Binding
MoveLeft key.Binding
MoveRight key.Binding
WordForward key.Binding
WordBackward key.Binding
LineStart key.Binding
LineEnd key.Binding
HalfPageDown key.Binding
HalfPageUp key.Binding
GotoPrefix key.Binding // initiates gg / gf
GotoEnd key.Binding
// Normal mode
Undo key.Binding
Redo key.Binding
InsertMode key.Binding
AppendAfter key.Binding
InsertAtStart key.Binding
ReplaceMode key.Binding
AppendEnd key.Binding
NewLineBelow key.Binding
NewLineAbove key.Binding
ToggleCheckbox key.Binding
InsertCheckbox key.Binding
VisualMode key.Binding
VisualLineMode key.Binding
Paste key.Binding
ReplacePrefix key.Binding // initiates r{char}
DeleteChar key.Binding
DeletePrefix key.Binding // initiates dd / dw
Indent key.Binding // > indent current line / selection
Dedent key.Binding // < dedent current line / selection
// Visual mode actions
Yank key.Binding
Cut key.Binding
Change key.Binding
SearchSelection key.Binding
// View mode
FoldExpand key.Binding
FoldCollapse key.Binding
// In-buffer search navigation (after :/pattern command)
SearchNext key.Binding // n – jump to next match
SearchPrev key.Binding // N – jump to previous match
// Universal
Escape key.Binding
}
KeyMap holds all key bindings for the viewer component. Each binding is a key.Binding that can be remapped by the user.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the default vim-style key bindings for the viewer.
func (*KeyMap) ApplyConfigKeys ¶
func (km *KeyMap) ApplyConfigKeys(vk config.ViewerKeys)
ApplyConfigKeys overlays user-configured key strings onto km, skipping any empty string (meaning "keep the default").
type Model ¶
type Model struct {
KeyMap KeyMap
// contains filtered or unexported fields
}
Model is the viewer component model.
func New ¶
func New() Model
New creates a new viewer Model with default key bindings and a single empty pane.
func (*Model) ActiveContent ¶
ActiveContent returns the raw content of the active tab, or "" if no tabs.
func (*Model) ActiveFilePath ¶
ActiveFilePath returns the file path of the active tab, or "" if no tabs.
func (*Model) ActiveMode ¶
ActiveMode returns the current mode of the active tab (ModeView if no tabs).
func (*Model) ActivePaneIndex ¶
ActivePaneIndex returns the index of the currently focused pane.
func (*Model) ActiveTabDiskChanged ¶
ActiveTabDiskChanged returns true if the active tab's file changed on disk since last load/save.
func (*Model) ActiveTabHasRecovery ¶
ActiveTabHasRecovery returns true if the active tab has a pending swap recovery.
func (*Model) ActiveTabIndex ¶
ActiveTabIndex returns the index of the currently active tab in the active pane.
func (*Model) ActiveTabSwapPath ¶
ActiveTabSwapPath returns the swap file path for the active tab.
func (*Model) ActiveTabWarning ¶
ActiveTabWarning returns the swap/disk-change state of the active tab for displaying a cmdbar warning. modified is true when the tab has unsaved edits (relevant when diskChanged is true to distinguish a conflict from a clean change).
func (*Model) ClearSearch ¶ added in v1.2.0
func (v *Model) ClearSearch()
ClearSearch clears the search state for the active tab.
func (*Model) ClearTabs ¶
func (v *Model) ClearTabs()
ClearTabs removes all open tabs and resets to a single empty pane.
func (*Model) CloseActivePane ¶
func (v *Model) CloseActivePane()
CloseActivePane closes the active pane. If the pane has tabs, the active tab is closed first; the pane then collapses if it is empty and not the last pane. If the pane is already empty and not the last pane, it collapses immediately.
func (*Model) CloseAllCleanTabs ¶
CloseAllCleanTabs removes tabs with no unsaved changes across all panes. Returns true if any tabs with unsaved changes remain.
func (*Model) CloseTab ¶
func (v *Model) CloseTab()
CloseTab closes the active tab (public wrapper for tui use).
func (*Model) CloseTabByPath ¶
CloseTabByPath closes the tab for the given path (public wrapper for tui use).
func (*Model) ConvertTabsToSpaces ¶ added in v0.9.0
ConvertTabsToSpaces replaces every \t in the active file's content with tabWidth spaces, marks the file modified, and reloads the textarea.
func (*Model) EnterInsertMode ¶ added in v1.2.0
func (v *Model) EnterInsertMode()
EnterInsertMode switches the active tab to insert mode (public wrapper).
func (*Model) EnterNormalMode ¶
func (v *Model) EnterNormalMode()
EnterNormalMode switches the active tab to normal mode (public wrapper).
func (*Model) ExitInsertMode ¶
func (v *Model) ExitInsertMode()
ExitInsertMode switches from insert to normal mode (public wrapper).
func (*Model) ExitNormalMode ¶
func (v *Model) ExitNormalMode()
ExitNormalMode switches the active tab back to view mode (public wrapper).
func (*Model) ExitVisualMode ¶
func (v *Model) ExitVisualMode()
ExitVisualMode switches from visual to normal mode (public wrapper).
func (*Model) FocusNeighbor ¶
FocusNeighbor moves focus to the neighboring pane in the given direction. Returns false if no neighbor exists.
func (*Model) GotoLine ¶ added in v0.9.0
GotoLine jumps the active tab's cursor to the given 1-based line number. Values < 1 clamp to line 1; values > totalLines clamp to the last line. Works in both View mode (t.cursor) and edit modes (textarea navigation).
func (*Model) HasPendingInput ¶
HasPendingInput returns true if the viewer is waiting for a second key in a multi-key sequence (d, g, r prefixes).
func (*Model) HasSearch ¶ added in v1.2.0
HasSearch returns true when the active tab has a non-empty search query.
func (*Model) HasUnsavedChanges ¶
HasUnsavedChanges returns true if any open tab has unsaved changes.
func (*Model) InsertAtCursor ¶
InsertAtCursor inserts text at the current cursor position in the textarea. Works in both Normal and Insert modes.
func (*Model) IsActiveModified ¶
IsActiveModified returns true if the active tab has unsaved changes.
func (*Model) ModeInfo ¶
ModeInfo returns the current mode and line, column numbers for display in the cmdbar.
func (*Model) MoveTabLeft ¶
func (v *Model) MoveTabLeft()
MoveTabLeft moves the active tab one position to the left (stops at index 0).
func (*Model) MoveTabRight ¶
func (v *Model) MoveTabRight()
MoveTabRight moves the active tab one position to the right (stops at last index).
func (*Model) MoveTabToNeighbor ¶
MoveTabToNeighbor moves the active tab to the neighboring pane in the given direction. Returns false if no neighbor exists or the active pane has no tabs.
func (*Model) NextTab ¶
func (v *Model) NextTab()
NextTab switches to the next tab (public wrapper).
func (*Model) PrevTab ¶
func (v *Model) PrevTab()
PrevTab switches to the previous tab (public wrapper).
func (*Model) RecoverActiveTab ¶
RecoverActiveTab loads swap content into the active tab. Returns false if the tab has no pending recovery.
func (*Model) RefreshAllTabs ¶
func (v *Model) RefreshAllTabs()
RefreshAllTabs re-renders glamour content and re-highlights all open tabs with the current theme. Call this after a theme change.
func (*Model) ReloadActiveTab ¶
ReloadActiveTab replaces the active tab's content with data from disk.
func (*Model) SearchMatchCount ¶ added in v1.2.0
SearchMatchCount returns the total number of matches in the active tab.
func (*Model) SearchNext ¶ added in v1.2.0
SearchNext advances to the next match (wrapping around at the end). Returns (found, wrapped): found is false when there are no matches; wrapped is true when the search cycled back to the beginning.
func (*Model) SearchPrev ¶ added in v1.2.0
SearchPrev moves to the previous match (wrapping around at the top). Returns (found, wrapped): found is false when there are no matches; wrapped is true when the search cycled back to the end.
func (*Model) SearchStatus ¶ added in v1.2.0
SearchStatus returns a short status string such as "/foo 2/5".
func (*Model) SelectionInfo ¶
SelectionInfo returns a human-readable description of the current visual selection, or "" when not in a visual mode.
func (*Model) SetActiveFilePath ¶
SetActiveFilePath updates the file path of the active tab.
func (*Model) SetActiveTabModified ¶
SetActiveTabModified marks the active tab as modified or clean. Intended for use in tests to simulate unsaved changes.
func (*Model) SetActiveTabRecovery ¶
SetActiveTabRecovery sets the hasRecovery flag on the active tab.
func (*Model) SetCheckboxStates ¶
SetCheckboxStates sets the ordered list of bracket characters used when cycling checkbox state with the toggle action. Pass nil to use the built-in default ([ ] >> [x]).
func (*Model) SetCustomTheme ¶
func (v *Model) SetCustomTheme(t *theme.CustomTheme)
SetCustomTheme sets the custom theme and resets the renderer.
func (*Model) SetDefaultMode ¶
SetDefaultMode sets the mode new tabs open in.
func (*Model) SetFoldLevel ¶
SetFoldLevel sets the default fold level.
func (*Model) SetSearch ¶ added in v1.2.0
SetSearch sets the search query for the active tab, computes all matches, and jumps to the first match. Returns the number of matches found.
func (*Model) SetTabSpaces ¶
SetTabSpaces sets the string inserted for a tab key press in insert mode.
func (*Model) SetTabWidth ¶ added in v0.9.0
SetTabWidth sets the visual column width used to expand \t characters in view/normal mode display. Has no effect when tabWidth <= 0.
func (*Model) SetTheme ¶
SetTheme sets the theme name and resets the renderer so it rebuilds next render.
func (*Model) SetupFileTracking ¶
SetupFileTracking initialises swap and disk-mtime tracking for the active tab.
func (*Model) SplitPane ¶ added in v1.2.0
func (v *Model) SplitPane(direction splitDir)
SplitPane is a helper function for SplitPaneVert & SplitPanHoriz. It handles the split logic, given some splitDir direction.
func (*Model) SplitPaneHoriz ¶
SplitPaneHoriz splits the active pane horizontally (top / bottom). Returns false if the pane is too short (min 10 lines per half). The current file is opened in the new pane so both halves show the same file.
func (*Model) SplitPaneVert ¶
SplitPaneVert splits the active pane vertically (left | right). Returns false if the pane is too narrow (min 40 chars per half). The current file is opened in the new pane so both halves show the same file.
func (*Model) Tick ¶
func (v *Model) Tick(writeSwapFn func(swapPath, filePath string, content []byte) error) (changedPath string, hasConflict bool)
Tick writes swap files for modified tabs and checks for on-disk mtime changes. writeSwapFn is called for each modified tab; errors are its responsibility to log. Returns the path of the active file if a disk change was newly detected, and whether that file has unsaved edits (conflict). Both are empty/false if no change.
func (*Model) ToggleAllFolds ¶ added in v1.2.0
ToggleAllFolds sets every fold on the active tab to folded=true (collapse) or folded=false (expand), then re-renders the tab.
func (*Model) ToggleCheckbox ¶
func (v *Model) ToggleCheckbox()
ToggleCheckbox toggles the checkbox on the current line (public wrapper).
type OpenLinkMsg ¶
type OpenLinkMsg struct{ Target string }
OpenLinkMsg is sent when gf detects a link to open.
type SearchMsg ¶
type SearchMsg struct{ Query string }
SearchMsg is sent when the user triggers a search from a visual selection.
type StatusMsg ¶
type StatusMsg struct{ Text string }
StatusMsg carries a status string from the viewer to the app for display.
type Styles ¶
type Styles struct {
Gutter, CursorGutter lipgloss.Style
Cursor lipgloss.Style
ActiveBorder, InactiveBorder, Title lipgloss.Style
Dim, ActiveTab, InactiveTab lipgloss.Style
}
Styles holds all lipgloss styles used by the viewer for rendering. These are set from the tui package after each theme change.