editor

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package editor provides UI components for code viewing and editing in the TUI. This file contains the diff viewer with line-by-line coloring. Uses the shared diff package for parsing and common functionality.

Package editor provides UI components for code viewing and editing in the TUI. This file contains the main Editor component for displaying code with syntax highlighting.

Package editor provides UI components for code viewing and editing in the TUI. This file contains syntax highlighting functionality using chroma.

Package editor provides UI components for code viewing and editing in the TUI. This file contains the TextArea component for text input with theme support.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTextAreaKeyMaps = TextAreaKeyMaps{
	Send: key.NewBinding(
		key.WithKeys("enter", "ctrl+s"),
		key.WithHelp("enter", "submit"),
	),
	OpenExternalEditor: key.NewBinding(
		key.WithKeys("ctrl+e"),
		key.WithHelp("ctrl+e", "open editor"),
	),
}

DefaultTextAreaKeyMaps returns the default key bindings for text area.

Functions

func GetSupportedLanguages

func GetSupportedLanguages() []string

GetSupportedLanguages returns a list of supported language identifiers.

func Highlight

func Highlight(code string, language string) string

Highlight highlights the given code with syntax highlighting using chroma. It takes the code content and an optional language identifier. If language is empty, it will attempt to detect the language from the filename.

func HighlightWithFilename

func HighlightWithFilename(code string, language string, filename string) string

HighlightWithFilename highlights the given code with syntax highlighting. It uses the filename to detect the language if language is not specified.

func ParseUnifiedDiff

func ParseUnifiedDiff(diffContent string) []diff.DiffHunk

ParseUnifiedDiff parses a unified diff string into structured DiffHunks. This is a wrapper that delegates to the shared diff package.

Types

type DiffViewer

type DiffViewer struct {
	*diff.Viewer
}

DiffViewer is a wrapper around the shared diff.Viewer for the editor component. It provides tea.Model interface compatibility.

func NewDiffViewer

func NewDiffViewer() *DiffViewer

NewDiffViewer creates a new diff viewer component.

func (*DiffViewer) Focused

func (dv *DiffViewer) Focused() bool

Focused returns whether the diff viewer is focused.

func (*DiffViewer) Init

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

Init implements tea.Model interface.

func (*DiffViewer) Render

func (dv *DiffViewer) Render(diffContent string) string

Render renders the diff viewer and returns the formatted string.

func (*DiffViewer) RenderSimple

func (dv *DiffViewer) RenderSimple(diffContent string) string

RenderSimple renders a diff without borders, useful for inline display.

func (*DiffViewer) SetDiffContent

func (dv *DiffViewer) SetDiffContent(content string) string

SetDiffContent sets the diff content to display.

func (*DiffViewer) SetFocused

func (dv *DiffViewer) SetFocused(focused bool)

SetFocused sets the focused state of the diff viewer.

func (*DiffViewer) SetSize

func (dv *DiffViewer) SetSize(width, height int)

SetSize sets the dimensions of the diff viewer.

func (*DiffViewer) Update

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

Update implements tea.Model interface.

func (*DiffViewer) View

func (dv *DiffViewer) View() string

View implements tea.Model interface.

type Editor

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

Editor is a component for viewing code with syntax highlighting.

func EditorFromFile

func EditorFromFile(filename string, content string) *Editor

EditorFromFile creates an editor component from file content.

func EditorWithLanguage

func EditorWithLanguage(filename string, content string, language string) *Editor

EditorWithLanguage creates an editor component with explicit language.

func NewEditor

func NewEditor() *Editor

NewEditor creates a new editor component.

func NewEditorWithContent

func NewEditorWithContent(content string) *Editor

NewEditorWithContent creates a new editor component with the given content.

func (*Editor) Focused

func (e *Editor) Focused() bool

Focused returns whether the editor is focused.

func (*Editor) GetContent

func (e *Editor) GetContent() string

GetContent returns the content of the editor.

func (*Editor) Init

func (e *Editor) Init() tea.Cmd

Init implements tea.Model interface.

func (*Editor) Render

func (e *Editor) Render() string

Render renders the editor with syntax highlighting.

func (*Editor) RenderSimple

func (e *Editor) RenderSimple() string

RenderSimple renders the editor without borders.

func (*Editor) SetContent

func (e *Editor) SetContent(content string)

SetContent sets the content of the editor.

func (*Editor) SetFilename

func (e *Editor) SetFilename(filename string)

SetFilename sets the filename for language detection.

func (*Editor) SetFocused

func (e *Editor) SetFocused(focused bool)

SetFocused sets the focused state of the editor.

func (*Editor) SetLanguage

func (e *Editor) SetLanguage(language string)

SetLanguage sets the language for syntax highlighting.

func (*Editor) SetRect

func (e *Editor) SetRect(rect layout.Rect)

SetRect sets the dimensions of the editor using a Rect.

func (*Editor) SetShowLineNumbers

func (e *Editor) SetShowLineNumbers(show bool)

SetShowLineNumbers sets whether to show line numbers.

func (*Editor) SetSize

func (e *Editor) SetSize(width, height int)

SetSize sets the dimensions of the editor (legacy compatibility).

func (*Editor) Update

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

Update implements tea.Model interface.

func (*Editor) View

func (e *Editor) View() string

View implements tea.Model interface.

type TextArea

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

TextArea is a component for text input with theme support.

func NewTextArea

func NewTextArea() *TextArea

NewTextArea creates a new text area component.

func NewTextAreaWithDimensions

func NewTextAreaWithDimensions(width, height int) *TextArea

NewTextAreaWithDimensions creates a new text area with given dimensions.

func TextAreaWithContent

func TextAreaWithContent(content string) *TextArea

TextAreaWithContent creates a text area with initial content.

func (*TextArea) Focused

func (t *TextArea) Focused() bool

Focused returns whether the text area is focused.

func (*TextArea) GetKeyBindings

func (t *TextArea) GetKeyBindings() []key.Binding

GetKeyBindings returns the key bindings for this component.

func (*TextArea) Init

func (t *TextArea) Init() tea.Cmd

Init initializes the text area (starts cursor blinking).

func (*TextArea) Reset

func (t *TextArea) Reset()

Reset clears the text area.

func (*TextArea) SetFocused

func (t *TextArea) SetFocused(focused bool)

SetFocused sets the focused state.

func (*TextArea) SetRect

func (t *TextArea) SetRect(rect layout.Rect)

SetRect sets the dimensions of the text area using a Rect.

func (*TextArea) SetSize

func (t *TextArea) SetSize(width, height int)

SetSize sets the dimensions of the text area.

func (*TextArea) SetValue

func (t *TextArea) SetValue(value string)

SetValue sets the text value.

func (*TextArea) Update

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

Update handles messages for the text area.

func (*TextArea) Value

func (t *TextArea) Value() string

Value returns the current text value.

func (*TextArea) View

func (t *TextArea) View() string

View renders the text area.

type TextAreaKeyMaps

type TextAreaKeyMaps struct {
	// Send binds to keys that submit the text (Enter, Ctrl+S)
	Send key.Binding
	// OpenExternalEditor binds to keys that open external editor (Ctrl+E)
	OpenExternalEditor key.Binding
}

TextAreaKeyMaps defines key bindings for the text area.

Jump to

Keyboard shortcuts

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