tui

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Help

func Help(km KeyMap) string

Help returns a formatted help string showing all keybindings.

func IsImageFile

func IsImageFile(ext string) bool

IsImageFile returns whether the given extension is a supported image format.

Types

type Bookmark

type Bookmark struct {
	Path   string
	Title  string
	Scroll int
}

Bookmark represents a saved location.

type CommandEntry

type CommandEntry struct {
	Name        string
	Description string
	Action      func() tea.Msg // returns a message to dispatch
}

CommandEntry represents an entry in the command palette.

type CommandPalette

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

CommandPalette manages the colon-mode command interface.

func NewCommandPalette

func NewCommandPalette() CommandPalette

NewCommandPalette creates a command palette with default commands.

func (*CommandPalette) Close

func (p *CommandPalette) Close()

Close deactivates the command palette.

func (*CommandPalette) Execute

func (p *CommandPalette) Execute() tea.Msg

Execute runs the selected command and returns its message.

func (*CommandPalette) HandleOpenInput

func (p *CommandPalette) HandleOpenInput(idx *index.Index) tea.Msg

HandleOpenInput handles the "open" command with fuzzy file matching.

func (*CommandPalette) IsActive

func (p *CommandPalette) IsActive() bool

IsActive returns whether the palette is open.

func (*CommandPalette) MoveDown

func (p *CommandPalette) MoveDown()

MoveDown moves the cursor down in the palette.

func (*CommandPalette) MoveUp

func (p *CommandPalette) MoveUp()

MoveUp moves the cursor up in the palette.

func (*CommandPalette) Open

func (p *CommandPalette) Open()

Open activates the command palette.

func (*CommandPalette) RegisterCommand

func (p *CommandPalette) RegisterCommand(cmd CommandEntry)

RegisterCommand adds a command to the palette.

func (*CommandPalette) RegisterCommands

func (p *CommandPalette) RegisterCommands(idx *index.Index, links *index.LinkGraph)

RegisterCommands sets up the standard command set for the TUI.

func (*CommandPalette) SetInput

func (p *CommandPalette) SetInput(s string)

SetInput updates the filter input.

func (CommandPalette) View

func (p CommandPalette) View() string

View renders the command palette overlay.

type FileListModel

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

FileListModel manages the file list panel with fuzzy filtering.

func NewFileListModel

func NewFileListModel(idx *index.Index) FileListModel

NewFileListModel creates a file list panel.

func (*FileListModel) ClearFilter

func (m *FileListModel) ClearFilter()

ClearFilter exits filter mode and resets the list.

func (*FileListModel) MoveDown

func (m *FileListModel) MoveDown()

MoveDown moves the cursor down.

func (*FileListModel) MoveUp

func (m *FileListModel) MoveUp()

MoveUp moves the cursor up.

func (*FileListModel) SelectByPath

func (m *FileListModel) SelectByPath(relPath string)

SelectByPath positions the cursor on the file with the given relative path. It expands any collapsed parent directories so the file is visible.

func (*FileListModel) Selected

func (m *FileListModel) Selected() *index.FileEntry

Selected returns the currently selected entry from filtered list.

func (*FileListModel) SelectedVisible

func (m *FileListModel) SelectedVisible() *index.FileEntry

SelectedVisible returns the entry for the current cursor in tree mode.

func (*FileListModel) SetFilter

func (m *FileListModel) SetFilter(query string)

SetFilter updates the fuzzy filter query and refilters.

func (*FileListModel) StartFilter

func (m *FileListModel) StartFilter()

StartFilter enters filter mode.

func (*FileListModel) ToggleDir

func (m *FileListModel) ToggleDir()

ToggleDir collapses or expands the directory at the cursor.

func (FileListModel) View

func (m FileListModel) View() string

View renders the file list.

type FileSelectedMsg

type FileSelectedMsg struct {
	Entry index.FileEntry
}

Message types for inter-component communication.

type HistoryEntry

type HistoryEntry struct {
	Path   string
	Scroll int
}

HistoryEntry records a navigation event for back/forward.

type ImageRenderer

type ImageRenderer struct{}

ImageRenderer handles image file display in the TUI. Uses a text-based info card because terminal image protocols (Kitty, iTerm2) are incompatible with Bubble Tea's alt-screen rendering — they cause duplication on resize and can't be scrolled or clipped to pane bounds.

func NewImageRenderer

func NewImageRenderer() *ImageRenderer

NewImageRenderer creates an image renderer.

func (*ImageRenderer) Render

func (r *ImageRenderer) Render(path string) string

Render returns a text-based info card for the image file.

type KeyMap

type KeyMap struct {
	Quit      key.Binding
	Up        key.Binding
	Down      key.Binding
	Enter     key.Binding
	Back      key.Binding
	Tab       key.Binding
	Search    key.Binding
	Help      key.Binding
	Follow    key.Binding
	Backlinks key.Binding
	TOC       key.Binding
	Bookmark  key.Binding
	Command   key.Binding
	CopyLink  key.Binding
	GitInfo   key.Binding
	Copy      key.Binding
	Reload    key.Binding
	HalfUp    key.Binding
	HalfDown  key.Binding
}

KeyMap defines all keybindings for the TUI.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default keybinding set.

func EmacsKeyMap

func EmacsKeyMap() KeyMap

EmacsKeyMap returns emacs-style keybindings.

func VimKeyMap

func VimKeyMap() KeyMap

VimKeyMap returns vim-style keybindings.

type LinkFollowMsg

type LinkFollowMsg struct {
	Target   string
	Fragment string // anchor fragment to scroll to
}

LinkFollowMsg is sent when the user follows a link.

type LinkNavigator

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

LinkNavigator manages link following with history.

func NewLinkNavigator

func NewLinkNavigator(graph *index.LinkGraph) *LinkNavigator

NewLinkNavigator creates a link navigator backed by a link graph.

func (*LinkNavigator) Back

func (n *LinkNavigator) Back() *HistoryEntry

Back returns the previous history entry, or nil if at the beginning.

func (*LinkNavigator) BacklinksAt

func (n *LinkNavigator) BacklinksAt(path string) []index.Link

BacklinksAt returns files linking to the given path.

func (n *LinkNavigator) CloseLinks()

CloseLinks dismisses the link selection overlay.

func (*LinkNavigator) Current

func (n *LinkNavigator) Current() *HistoryEntry

Current returns the current history entry, or nil if empty.

func (*LinkNavigator) Forward

func (n *LinkNavigator) Forward() *HistoryEntry

Forward returns the next history entry, or nil if at the end.

func (n *LinkNavigator) IsShowingLinks() bool

IsShowingLinks returns whether the link selection overlay is visible.

func (*LinkNavigator) LinkMoveDown

func (n *LinkNavigator) LinkMoveDown()

LinkMoveDown moves the cursor down in the link selection overlay.

func (*LinkNavigator) LinkMoveUp

func (n *LinkNavigator) LinkMoveUp()

LinkMoveUp moves the cursor up in the link selection overlay.

func (*LinkNavigator) LinkOverlayView

func (n *LinkNavigator) LinkOverlayView() string

LinkOverlayView renders the link selection overlay.

func (*LinkNavigator) LinkSelect

func (n *LinkNavigator) LinkSelect() (string, string)

LinkSelect returns the currently selected link target and fragment, then closes the overlay.

func (*LinkNavigator) LinksAt

func (n *LinkNavigator) LinksAt(path string) []index.Link

LinksAt returns the forward links from the current file.

func (*LinkNavigator) Navigate

func (n *LinkNavigator) Navigate(path string, scroll int)

Navigate pushes a new entry onto the history stack.

func (n *LinkNavigator) ShowLinks(path string) (target, fragment string)

ShowLinks opens the link selection overlay for the given file. If there is exactly one link, it returns the target directly. Returns the single target or empty string if overlay is shown.

type LinkSelectMsg

type LinkSelectMsg struct {
	Target string
}

LinkSelectMsg is sent when the user picks a link from the overlay.

type Model

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

Model is the root Bubble Tea model for the TUI.

func New

func New(cfg *config.Config, idx *index.Index, links *index.LinkGraph, plugins *plugin.Registry) *Model

New creates a new root TUI model.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init implements tea.Model.

func (*Model) SelectFile

func (m *Model) SelectFile(relPath string)

SelectFile pre-selects a file by relative path on startup. In single-file mode (1 non-dir entry), hides the file list and focuses the preview pane for full-width content viewing. The preview auto-loads via Init(). Must be called before Run().

func (*Model) SetRemoteInfo

func (m *Model) SetRemoteInfo(info *RemoteInfo)

SetRemoteInfo updates the remote connection display state. Safe to call from any goroutine.

func (*Model) Update

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

func (*Model) View

func (m *Model) View() string

View implements tea.Model.

type NavigateMsg struct {
	Path string
}

type Panel

type Panel int

Panel identifies which panel is currently focused.

const (
	PanelFileList Panel = iota
	PanelPreview
	PanelSide
)

type PanelSelectMsg

type PanelSelectMsg struct {
	Path   string // for backlinks/bookmarks: file to navigate to
	Line   int    // for TOC: line to scroll to
	Scroll int    // for bookmarks: scroll position to restore
}

PanelSelectMsg is sent when the user selects an item in a side panel.

type PanelType

type PanelType int

PanelType identifies the type of side panel displayed.

const (
	PanelNone PanelType = iota
	PanelTOC
	PanelBacklinks
	PanelGitInfo
	PanelBookmarks
)

type PreviewLoadedMsg

type PreviewLoadedMsg struct {
	Path    string
	Content string
}

type PreviewModel

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

PreviewModel renders file content in the preview pane.

func NewPreviewModel

func NewPreviewModel() PreviewModel

NewPreviewModel creates a preview pane.

func (*PreviewModel) CursorDown

func (m *PreviewModel) CursorDown()

CursorDown moves the cursor down one line, scrolling when hitting the scrolloff margin.

func (*PreviewModel) CursorTo

func (m *PreviewModel) CursorTo(line int)

CursorTo moves the cursor to a specific line, adjusting scroll.

func (*PreviewModel) CursorUp

func (m *PreviewModel) CursorUp()

CursorUp moves the cursor up one line, scrolling when hitting the scrolloff margin.

func (*PreviewModel) EnterSearchMode

func (m *PreviewModel) EnterSearchMode()

EnterSearchMode activates search input in the preview pane.

func (*PreviewModel) EnterVisualMode

func (m *PreviewModel) EnterVisualMode()

EnterVisualMode starts line selection at the current cursor position.

func (*PreviewModel) ExitSearchMode

func (m *PreviewModel) ExitSearchMode()

ExitSearchMode deactivates search input but keeps match highlights.

func (*PreviewModel) ExitVisualMode

func (m *PreviewModel) ExitVisualMode()

ExitVisualMode clears selection.

func (*PreviewModel) NextMatch

func (m *PreviewModel) NextMatch()

NextMatch advances to the next search match.

func (*PreviewModel) PrevMatch

func (m *PreviewModel) PrevMatch()

PrevMatch goes to the previous search match.

func (*PreviewModel) ScrollDown

func (m *PreviewModel) ScrollDown(lines int)

ScrollDown scrolls the preview down.

func (*PreviewModel) ScrollToBottom

func (m *PreviewModel) ScrollToBottom()

ScrollToBottom scrolls to the end of content.

func (*PreviewModel) ScrollUp

func (m *PreviewModel) ScrollUp(lines int)

ScrollUp scrolls the preview up.

func (*PreviewModel) SearchBackspace

func (m *PreviewModel) SearchBackspace()

SearchBackspace removes the last character from the search query.

func (*PreviewModel) SearchHistoryDown

func (m *PreviewModel) SearchHistoryDown()

SearchHistoryDown cycles to the next (more recent) search query.

func (*PreviewModel) SearchHistoryUp

func (m *PreviewModel) SearchHistoryUp()

SearchHistoryUp cycles to the previous search query.

func (*PreviewModel) SearchInput

func (m *PreviewModel) SearchInput(r rune)

SearchInput appends a character to the search query and recomputes matches.

func (*PreviewModel) SelectedSourceLines

func (m *PreviewModel) SelectedSourceLines() (startLine, endLine int)

SelectedSourceLines returns the 1-based source line range for the visual selection. For code files (1:1 mapping), this is exact. For markdown, it's approximate.

func (*PreviewModel) SetContent

func (m *PreviewModel) SetContent(path, content string)

SetContent updates the preview with rendered content.

func (*PreviewModel) SetSourceInfo

func (m *PreviewModel) SetSourceInfo(lineCount int, isCode bool)

SetSourceInfo stores metadata about the source file for line mapping.

func (*PreviewModel) ToggleReadingGuide

func (m *PreviewModel) ToggleReadingGuide()

ToggleReadingGuide toggles the full-row cursor highlight.

func (*PreviewModel) ToggleSearchRegex

func (m *PreviewModel) ToggleSearchRegex()

ToggleSearchRegex toggles between substring and regex search modes.

func (PreviewModel) View

func (m PreviewModel) View() string

View renders the preview content with line numbers.

func (*PreviewModel) VisualCursorDown

func (m *PreviewModel) VisualCursorDown()

VisualCursorDown moves the visual cursor down.

func (*PreviewModel) VisualCursorUp

func (m *PreviewModel) VisualCursorUp()

VisualCursorUp moves the visual cursor up.

type RemoteInfo

type RemoteInfo struct {
	Display  string // "user@host:/path"
	State    string // "Connected", "Reconnecting", "Disconnected"
	LastSync string // "5s ago", "syncing..."
}

RemoteInfo holds remote connection display state for the TUI.

type SidePanelModel

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

SidePanelModel manages the optional side panel (TOC, backlinks, etc.).

func NewSidePanelModel

func NewSidePanelModel() SidePanelModel

NewSidePanelModel creates a side panel model.

func (*SidePanelModel) AddBookmark

func (m *SidePanelModel) AddBookmark(bm Bookmark)

AddBookmark adds a bookmark.

func (*SidePanelModel) MoveDown

func (m *SidePanelModel) MoveDown()

MoveDown moves the panel cursor down.

func (*SidePanelModel) MoveUp

func (m *SidePanelModel) MoveUp()

MoveUp moves the panel cursor up.

func (*SidePanelModel) RemoveBookmark

func (m *SidePanelModel) RemoveBookmark(idx int)

RemoveBookmark removes a bookmark by index.

func (*SidePanelModel) Select

func (m *SidePanelModel) Select() *PanelSelectMsg

Select returns information about the currently selected item.

func (m *SidePanelModel) SetBacklinks(links []index.Link)

SetBacklinks updates the backlinks list from the link graph.

func (*SidePanelModel) SetGitInfo

func (m *SidePanelModel) SetGitInfo(repoRoot, filePath string)

SetGitInfo updates the git info panel content.

func (*SidePanelModel) SetTOC

func (m *SidePanelModel) SetTOC(entries []TOCEntry)

SetTOC updates the table of contents entries.

func (*SidePanelModel) SetTOCFromMarkdown

func (m *SidePanelModel) SetTOCFromMarkdown(source string)

SetTOCFromMarkdown extracts headings from raw markdown source and updates TOC.

func (*SidePanelModel) Toggle

func (m *SidePanelModel) Toggle(pt PanelType)

Toggle switches between showing and hiding the given panel type.

func (*SidePanelModel) Type

func (m *SidePanelModel) Type() PanelType

Type returns the current panel type.

func (*SidePanelModel) TypeName

func (m *SidePanelModel) TypeName() string

TypeName returns a display name for the current panel type.

func (SidePanelModel) View

func (m SidePanelModel) View() string

View renders the side panel.

func (*SidePanelModel) Visible

func (m *SidePanelModel) Visible() bool

Visible returns whether the side panel is currently shown.

type StatusBarModel

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

StatusBarModel renders the bottom status bar.

func NewStatusBarModel

func NewStatusBarModel() StatusBarModel

NewStatusBarModel creates a status bar.

func (*StatusBarModel) SetFile

func (m *StatusBarModel) SetFile(path string)

SetFile updates the displayed file path.

func (*StatusBarModel) SetMessage

func (m *StatusBarModel) SetMessage(msg string)

SetMessage sets a temporary status message.

func (*StatusBarModel) SetMode

func (m *StatusBarModel) SetMode(mode string)

SetMode sets the current input mode display.

func (StatusBarModel) View

func (m StatusBarModel) View() string

View renders the status bar.

type StatusMsg

type StatusMsg struct {
	Text string
}

type TOCEntry

type TOCEntry struct {
	Level int
	Text  string
	Line  int
}

TOCEntry represents a heading in the table of contents.

Jump to

Keyboard shortcuts

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