visual

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

README

Visual Interface Components

This package provides rich terminal-based visual interfaces for file editing and diff viewing.

Components

diff_view.go
  • Rich terminal diff display with syntax highlighting
  • Multiple diff modes:
    • Side-by-side diff mode
    • Unified diff mode
  • Interactive navigation controls
  • Approval/rejection interface for AI edits
  • Integration with existing Bubble Tea UI
file_view.go
  • Interactive file tree navigation
  • Fuzzy search integration for quick file finding
  • Preview pane with syntax highlighting
  • Git status indicators
  • File selection and action controls
  • Keyboard shortcuts and navigation
editor_view.go
  • Interactive file editing interface
  • Real-time diff preview during editing
  • Undo/redo capabilities
  • Search and replace functionality
  • Integration with tree-sitter for syntax awareness

Features

  • Rich Terminal UI: Leverages Bubble Tea for smooth interactions
  • Syntax Highlighting: Code-aware display using existing glamour integration
  • Interactive Navigation: Keyboard-driven interface design
  • Real-time Preview: Live diff updates during editing
  • Git Integration: Visual indicators for version control status

Usage

This package provides:

  • Visual diff approval interface for AI-suggested edits
  • Interactive file browser for context exploration
  • Rich editing experience within the terminal
  • Integration with chat interface for seamless workflow
  • Keyboard-driven productivity features

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareDiffs

func CompareDiffs(diff1, diff2 []diffmatchpatch.Diff) string

CompareDiffs compares two diff results and highlights differences

func ShowDiffPreview

func ShowDiffPreview(original, modified string, maxLines int) string

ShowDiffPreview shows a quick diff preview without interaction

Types

type DiffKeyMap

type DiffKeyMap struct {
	Approve  key.Binding
	Reject   key.Binding
	Edit     key.Binding
	Save     key.Binding
	Cancel   key.Binding
	Up       key.Binding
	Down     key.Binding
	PageUp   key.Binding
	PageDown key.Binding
	Home     key.Binding
	End      key.Binding
	Help     key.Binding
	Quit     key.Binding
}

DiffKeyMap defines keyboard shortcuts for diff view

type DiffMode

type DiffMode string

DiffMode represents different diff display modes

const (
	DiffModeUnified    DiffMode = "unified"
	DiffModeSideBySide DiffMode = "side-by-side"
	DiffModeInline     DiffMode = "inline"
)

type DiffStyles

type DiffStyles struct {
	Base       lipgloss.Style
	Header     lipgloss.Style
	Footer     lipgloss.Style
	LineNumber lipgloss.Style
	Added      lipgloss.Style
	Removed    lipgloss.Style
	Modified   lipgloss.Style
	Context    lipgloss.Style
	Highlight  lipgloss.Style
	Error      lipgloss.Style
	Success    lipgloss.Style
}

DiffStyles defines styling for diff view components

type DiffView

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

DiffView represents a visual diff display component

func NewDiffView

func NewDiffView(config DiffViewConfig) *DiffView

NewDiffView creates a new diff view instance

func (*DiffView) GetAction

func (dv *DiffView) GetAction() DiffViewAction

GetAction returns the last user action

func (*DiffView) Init

func (dv *DiffView) Init() tea.Cmd

Init initializes the diff view model

func (*DiffView) IsApproved

func (dv *DiffView) IsApproved() bool

IsApproved returns whether the diff was approved

func (*DiffView) Resize

func (dv *DiffView) Resize(width, height int)

Resize updates the diff view dimensions

func (*DiffView) SetContent

func (dv *DiffView) SetContent(original, modified, filePath string)

SetContent sets the original and modified content for diff

func (*DiffView) SetDiff

func (dv *DiffView) SetDiff(diffBlocks []edit.DiffFormat, filePath string)

SetDiff sets the diff content directly from edit operations

func (*DiffView) Update

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

Update handles tea.Msg updates

func (*DiffView) View

func (dv *DiffView) View() string

View renders the diff view

type DiffViewAction

type DiffViewAction string

DiffViewAction represents user actions in the diff view

const (
	ActionApprove DiffViewAction = "approve"
	ActionReject  DiffViewAction = "reject"
	ActionEdit    DiffViewAction = "edit"
	ActionSave    DiffViewAction = "save"
	ActionCancel  DiffViewAction = "cancel"
)

type DiffViewConfig

type DiffViewConfig struct {
	Mode            DiffMode `json:"mode"`
	ShowLineNumbers bool     `json:"show_line_numbers"`
	TabSize         int      `json:"tab_size"`
	ContextLines    int      `json:"context_lines"`
	EnableSyntax    bool     `json:"enable_syntax"`
	AutoApprove     bool     `json:"auto_approve"`
	Theme           string   `json:"theme"`
}

DiffViewConfig configures the diff view behavior

type DiffViewResult

type DiffViewResult struct {
	Action   DiffViewAction `json:"action"`
	Approved bool           `json:"approved"`
	FilePath string         `json:"file_path"`
	Duration time.Duration  `json:"duration"`
	Error    string         `json:"error,omitempty"`
}

DiffViewResult represents the result of a diff view session

func RunDiffView

func RunDiffView(original, modified, filePath string, config DiffViewConfig) (*DiffViewResult, error)

RunDiffView runs an interactive diff view session

type EditorAction

type EditorAction string

EditorAction represents user actions in the editor

const (
	EditorActionSave    EditorAction = "save"
	EditorActionCancel  EditorAction = "cancel"
	EditorActionPreview EditorAction = "preview"
	EditorActionFormat  EditorAction = "format"
	EditorActionUndo    EditorAction = "undo"
	EditorActionRedo    EditorAction = "redo"
	EditorActionFind    EditorAction = "find"
	EditorActionReplace EditorAction = "replace"
	EditorActionQuit    EditorAction = "quit"
)

type EditorKeyMap

type EditorKeyMap struct {
	Save        key.Binding
	Cancel      key.Binding
	Preview     key.Binding
	Format      key.Binding
	Undo        key.Binding
	Redo        key.Binding
	Find        key.Binding
	Replace     key.Binding
	SwitchMode  key.Binding
	ToggleWrap  key.Binding
	LineNumbers key.Binding
	Quit        key.Binding
}

EditorKeyMap defines keyboard shortcuts for the editor

type EditorMode

type EditorMode string

EditorMode represents different editor modes

const (
	EditorModeEdit    EditorMode = "edit"
	EditorModePreview EditorMode = "preview"
	EditorModeSplit   EditorMode = "split"
	EditorModeDiff    EditorMode = "diff"
)

type EditorStyles

type EditorStyles struct {
	Base       lipgloss.Style
	Header     lipgloss.Style
	Footer     lipgloss.Style
	Editor     lipgloss.Style
	Preview    lipgloss.Style
	LineNumber lipgloss.Style
	Cursor     lipgloss.Style
	Selection  lipgloss.Style
	Status     lipgloss.Style
	Error      lipgloss.Style
	Success    lipgloss.Style
	Modified   lipgloss.Style
	Border     lipgloss.Style
}

EditorStyles defines styling for editor components

type EditorView

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

EditorView represents an interactive code editor component

func NewEditorView

func NewEditorView(config EditorViewConfig, fileEditor *edit.FileEditor, parser *treesitter.TreeSitterParser) *EditorView

NewEditorView creates a new editor instance

func (*EditorView) GetAction

func (ev *EditorView) GetAction() EditorAction

GetAction returns the last user action

func (*EditorView) GetContent

func (ev *EditorView) GetContent() string

GetContent returns the current editor content

func (*EditorView) Init

func (ev *EditorView) Init() tea.Cmd

Resize updates the editor dimensions Init initializes the editor view model

func (*EditorView) IsModified

func (ev *EditorView) IsModified() bool

IsModified returns whether the content has been modified

func (*EditorView) IsSaved

func (ev *EditorView) IsSaved() bool

IsSaved returns whether the content has been saved

func (*EditorView) LoadFile

func (ev *EditorView) LoadFile(filePath string) error

LoadFile loads content from a file

func (*EditorView) Resize

func (ev *EditorView) Resize(width, height int)

func (*EditorView) SaveFile

func (ev *EditorView) SaveFile() error

SaveFile saves the current content to file

func (*EditorView) SetContent

func (ev *EditorView) SetContent(content string)

SetContent sets the editor content directly

func (*EditorView) Update

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

Update handles tea.Msg updates

func (*EditorView) View

func (ev *EditorView) View() string

View renders the editor view

type EditorViewConfig

type EditorViewConfig struct {
	FilePath        string              `json:"file_path"`
	Language        treesitter.Language `json:"language"`
	Mode            EditorMode          `json:"mode"`
	ShowLineNumbers bool                `json:"show_line_numbers"`
	TabSize         int                 `json:"tab_size"`
	WordWrap        bool                `json:"word_wrap"`
	AutoSave        bool                `json:"auto_save"`
	AutoFormat      bool                `json:"auto_format"`
	SyntaxHighlight bool                `json:"syntax_highlight"`
	LivePreview     bool                `json:"live_preview"`
	VimMode         bool                `json:"vim_mode"`
	Theme           string              `json:"theme"`
	MaxFileSize     int64               `json:"max_file_size"`
}

EditorViewConfig configures the editor behavior

type EditorViewResult

type EditorViewResult struct {
	Action   EditorAction  `json:"action"`
	Content  string        `json:"content,omitempty"`
	FilePath string        `json:"file_path"`
	Saved    bool          `json:"saved"`
	Modified bool          `json:"modified"`
	Duration time.Duration `json:"duration"`
	Error    string        `json:"error,omitempty"`
}

EditorViewResult represents the result of an editor session

func RunEditorView

func RunEditorView(config EditorViewConfig, fileEditor *edit.FileEditor, parser *treesitter.TreeSitterParser) (*EditorViewResult, error)

RunEditorView runs an interactive editor session

type FileItem

type FileItem struct {
	Name         string                 `json:"name"`
	Path         string                 `json:"path"`
	RelativePath string                 `json:"relative_path"`
	IsDir        bool                   `json:"is_dir"`
	Size         int64                  `json:"size"`
	ModTime      time.Time              `json:"mod_time"`
	GitStatus    string                 `json:"git_status,omitempty"`
	Language     treesitter.Language    `json:"language,omitempty"`
	Preview      string                 `json:"preview,omitempty"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
}

FileItem represents a file or directory in the browser

type FileListItem

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

FileListItem implements list.Item for the file list

func (FileListItem) Description

func (i FileListItem) Description() string

func (FileListItem) FilterValue

func (i FileListItem) FilterValue() string

func (FileListItem) Title

func (i FileListItem) Title() string

type FileView

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

FileView represents an interactive file browser component

func NewFileView

func NewFileView(config FileViewConfig, discovery *appcontext.FileDiscovery, parser *treesitter.TreeSitterParser) *FileView

NewFileView creates a new file browser instance

func (*FileView) GetAction

func (fv *FileView) GetAction() FileViewAction

GetAction returns the last user action

func (*FileView) GetSelectedFile

func (fv *FileView) GetSelectedFile() *FileItem

GetSelectedFile returns the currently selected file

func (*FileView) Init

func (fv *FileView) Init() tea.Cmd

Init initializes the file view model

func (*FileView) LoadDirectory

func (fv *FileView) LoadDirectory(path string) error

LoadDirectory loads files from the specified directory

func (*FileView) Resize

func (fv *FileView) Resize(width, height int)

Resize updates the file view dimensions

func (*FileView) Search

func (fv *FileView) Search(query string)

Search performs fuzzy search on file names

func (*FileView) Update

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

Update handles tea.Msg updates

func (*FileView) View

func (fv *FileView) View() string

View renders the file view

type FileViewAction

type FileViewAction string

FileViewAction represents user actions in the file view

const (
	FileActionSelect  FileViewAction = "select"
	FileActionEdit    FileViewAction = "edit"
	FileActionPreview FileViewAction = "preview"
	FileActionSearch  FileViewAction = "search"
	FileActionRefresh FileViewAction = "refresh"
	FileActionBack    FileViewAction = "back"
	FileActionQuit    FileViewAction = "quit"
)

type FileViewConfig

type FileViewConfig struct {
	RootPath        string       `json:"root_path"`
	Mode            FileViewMode `json:"mode"`
	ShowHidden      bool         `json:"show_hidden"`
	ShowGitStatus   bool         `json:"show_git_status"`
	EnablePreview   bool         `json:"enable_preview"`
	MaxPreviewLines int          `json:"max_preview_lines"`
	FuzzySearch     bool         `json:"fuzzy_search"`
	PreviewSyntax   bool         `json:"preview_syntax"`
	TreeIndent      int          `json:"tree_indent"`
	Extensions      []string     `json:"extensions,omitempty"`
	ExcludePatterns []string     `json:"exclude_patterns,omitempty"`
}

FileViewConfig configures the file browser behavior

type FileViewKeyMap

type FileViewKeyMap struct {
	Select   key.Binding
	Edit     key.Binding
	Preview  key.Binding
	Search   key.Binding
	Refresh  key.Binding
	Back     key.Binding
	Up       key.Binding
	Down     key.Binding
	Left     key.Binding
	Right    key.Binding
	PageUp   key.Binding
	PageDown key.Binding
	Home     key.Binding
	End      key.Binding
	Enter    key.Binding
	Escape   key.Binding
	Tab      key.Binding
	Help     key.Binding
	Quit     key.Binding
}

FileViewKeyMap defines keyboard shortcuts for file view

type FileViewMode

type FileViewMode string

FileViewMode represents different file browser modes

const (
	FileViewModeTree    FileViewMode = "tree"
	FileViewModeList    FileViewMode = "list"
	FileViewModeSearch  FileViewMode = "search"
	FileViewModePreview FileViewMode = "preview"
)

type FileViewResult

type FileViewResult struct {
	Action       FileViewAction `json:"action"`
	SelectedFile *FileItem      `json:"selected_file,omitempty"`
	CurrentPath  string         `json:"current_path"`
	Duration     time.Duration  `json:"duration"`
	Error        string         `json:"error,omitempty"`
}

FileViewResult represents the result of a file view session

func RunFileView

func RunFileView(config FileViewConfig, discovery *appcontext.FileDiscovery, parser *treesitter.TreeSitterParser) (*FileViewResult, error)

RunFileView runs an interactive file browser session

type FileViewStyles

type FileViewStyles struct {
	Base        lipgloss.Style
	Header      lipgloss.Style
	Footer      lipgloss.Style
	List        lipgloss.Style
	Preview     lipgloss.Style
	Search      lipgloss.Style
	Directory   lipgloss.Style
	File        lipgloss.Style
	Selected    lipgloss.Style
	GitAdded    lipgloss.Style
	GitModified lipgloss.Style
	GitDeleted  lipgloss.Style
	Error       lipgloss.Style
	Loading     lipgloss.Style
	Border      lipgloss.Style
}

FileViewStyles defines styling for file view components

Jump to

Keyboard shortcuts

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