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) ClearTabs()
- func (v *Model) CloseActivePane()
- func (v *Model) CloseAllCleanTabs() bool
- func (v *Model) CloseTab()
- func (v *Model) CloseTabByPath(path string)
- 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) HasPendingInput() 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() (string, 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) 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) SetSize(w, h int)
- func (v *Model) SetSplashContent(s string)
- func (v *Model) SetStyles(s Styles)
- func (v *Model) SetTabSpaces(s string)
- func (v *Model) SetTheme(s string)
- func (v *Model) SetupFileTracking(swapPath string, mtime time.Time)
- 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) 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
// Visual mode actions
Yank key.Binding
Cut key.Binding
Change key.Binding
SearchSelection key.Binding
// View mode
FoldPrefix key.Binding // initiates za / zR / zM
// 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) 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 pane 0. If the pane is already empty and not pane 0, 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) 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) HasPendingInput ¶
HasPendingInput returns true if the viewer is waiting for a second key in a multi-key sequence (d, g, r prefixes).
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 label 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) 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) SetSplashContent ¶
SetSplashContent sets text to display centered in the viewer when no files are open. Pass an empty string to clear it.
func (*Model) SetTabSpaces ¶
SetTabSpaces sets the string inserted for a tab key press in insert mode.
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) SplitPaneHoriz ¶
SplitPaneHoriz splits the active pane horizontally (top / bottom). Returns false if the pane is too short (min 10 lines per half).
func (*Model) SplitPaneVert ¶
SplitPaneVert splits the active pane vertically (left | right). Returns false if the pane is too narrow (min 40 chars per half).
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) 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.