Documentation
¶
Overview ¶
internal/editor/buffer.go
internal/editor/cursor.go
internal/editor/display.go
internal/editor/editor.go
internal/editor/ghost.go
internal/editor/input.go
internal/editor/insert.go
internal/editor/key.go
internal/editor/mode.go
internal/editor/normal.go
internal/editor/undo.go
Index ¶
- Constants
- func AnnotateDuration(out io.Writer, termWidth, outputLines, cmdLines int, durationMs int64, ...)
- type Action
- type Buffer
- type Completion
- type CompletionItem
- type Config
- type Cursor
- type Display
- func (d *Display) AnnotateDuration(outputLines int, durationMs int64)
- func (d *Display) Clear()
- func (d *Display) ClearCompletionMenu(numItems int)
- func (d *Display) Finalize(buf *Buffer)
- func (d *Display) FinalizedLines() int
- func (d *Display) Render(buf *Buffer, cur *Cursor, hasSelection bool)
- func (d *Display) RenderCompletionMenu(items []CompletionItem, selected, startCol int)
- func (d *Display) RenderWithGhost(buf *Buffer, cur *Cursor, hasSelection bool, ghostText string, ...)
- func (d *Display) Resize(width, height int)
- func (d *Display) SetGutter(enabled bool)
- func (d *Display) SetInputBgColor(hexColor string)
- func (d *Display) SetMode(mode string)
- func (d *Display) SetPrompt(prompt string)
- func (d *Display) SetPromptWidth(w int)
- func (d *Display) SetScrollbarColor(hexColor string)
- type Editor
- func (e *Editor) ClearGhostText()
- func (e *Editor) Run(ctx context.Context) (Result, error)
- func (e *Editor) SetGhostText(text string)
- func (e *Editor) SetGhostTextStreaming(textCh <-chan string, errCh <-chan error)
- func (e *Editor) SetInitialText(text string)
- func (e *Editor) SetPromptWidth(cols int)
- func (e *Editor) SetStreamingModel(model string)
- type EditorState
- type GhostText
- func (g *GhostText) AcceptAll() string
- func (g *GhostText) AcceptChar() string
- func (g *GhostText) AcceptWord() string
- func (g *GhostText) Append(text string)
- func (g *GhostText) Clear()
- func (g *GhostText) IsEmpty() bool
- func (g *GhostText) Remaining() string
- func (g *GhostText) Set(text string)
- func (g *GhostText) SetStreaming(streaming bool)
- type GhostTextChan
- type InputReader
- type InsertMode
- type Key
- type KeyCode
- type Mode
- type ModeResult
- type NormalMode
- type Position
- type Result
- type Snapshot
- type UndoStack
Constants ¶
const DefaultMaxPasteSize uint = 10 * 1024 * 1024
DefaultMaxPasteSize is the default maximum size of pasted content (10MB). Prevents memory exhaustion from extremely large pastes.
Variables ¶
This section is empty.
Functions ¶
func AnnotateDuration ¶
func AnnotateDuration(out io.Writer, termWidth, outputLines, cmdLines int, durationMs int64, bgColor string)
AnnotateDuration writes execution duration to the right side of a previous command line. Call after command execution. outputLines = lines of output, cmdLines = lines of command.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer holds the text content as a slice of lines.
func NewBufferFromString ¶
NewBufferFromString creates a buffer from a string.
func (*Buffer) ReplaceLine ¶
ReplaceLine replaces the content of a line (0-indexed).
type Completion ¶
Completion represents a completion candidate.
type CompletionItem ¶
CompletionItem is passed to display for rendering.
type Config ¶
type Config struct {
Keybindings string // "helix", "emacs", "vim"
HistoryFunc func(dir int, currentLine string) string // -1=prev, +1=next; currentLine is for saving
CompleteFunc func(line string, pos int) []Completion // Tab completion
PrefetchFunc func(line string, pos int) // Background completion prefetch (on space)
OnInputReady func() // Called after editor chrome is rendered, before input loop
Gutter bool // Show gutter indicator
Prompt string // Prompt string to display before input
InputBgColor string // Background color for submitted input (hex)
ScrollbarColor string // Foreground color for scrollbars (hex)
MaxPasteSize uint // Maximum paste size in bytes (default 10MB)
}
Config configures the editor.
type Cursor ¶
type Cursor struct {
Pos Position // Current cursor position
Anchor *Position // Selection anchor (nil if no selection)
}
Cursor tracks position and optional selection anchor.
func (*Cursor) ClearSelection ¶
func (c *Cursor) ClearSelection()
ClearSelection removes the selection.
func (*Cursor) HasSelection ¶
HasSelection returns true if there's an active selection.
func (*Cursor) SelectionRange ¶
SelectionRange returns start and end positions (normalized so start < end).
func (*Cursor) StartSelection ¶
func (c *Cursor) StartSelection()
StartSelection begins a selection at the current position.
type Display ¶
type Display struct {
// contains filtered or unexported fields
}
Display handles terminal rendering.
func NewDisplay ¶
NewDisplay creates a new display.
func (*Display) AnnotateDuration ¶
AnnotateDuration adds execution duration to the right side of the command line. Must be called after command execution, with outputLines = lines of command output.
func (*Display) ClearCompletionMenu ¶
ClearCompletionMenu removes the completion menu from display.
func (*Display) Finalize ¶
Finalize leaves the content on screen and moves to a new line. Re-renders with background highlight to distinguish from output.
func (*Display) FinalizedLines ¶
FinalizedLines returns how many lines were rendered by Finalize. Used to position cursor for post-execution annotations.
func (*Display) RenderCompletionMenu ¶
func (d *Display) RenderCompletionMenu(items []CompletionItem, selected, startCol int)
RenderCompletionMenu draws the completion dropdown below the cursor.
func (*Display) RenderWithGhost ¶
func (d *Display) RenderWithGhost(buf *Buffer, cur *Cursor, hasSelection bool, ghostText string, streaming, fromAgent bool, modelName string)
RenderWithGhost draws the buffer with inline ghost text suggestion. Ghost text appears after the cursor in dim gray, showing the suggested completion. fromAgent indicates whether this is an agent suggestion (show hints) or prediction (fish-style).
func (*Display) SetInputBgColor ¶
SetInputBgColor sets the background color for submitted input. hexColor should be in format "#RRGGBB".
func (*Display) SetPromptWidth ¶
SetPromptWidth sets the prompt width for cursor positioning.
func (*Display) SetScrollbarColor ¶
SetScrollbarColor sets the foreground color for scrollbars. hexColor should be in format "#RRGGBB".
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor is the main editor instance.
func (*Editor) ClearGhostText ¶
func (e *Editor) ClearGhostText()
ClearGhostText removes any ghost text.
func (*Editor) SetGhostText ¶
SetGhostText sets inline suggestion text that appears after the cursor.
func (*Editor) SetGhostTextStreaming ¶
SetGhostTextStreaming sets up streaming ghost text from channels. Text chunks arrive on textCh, errors on errCh.
func (*Editor) SetInitialText ¶
SetInitialText sets the initial text in the editor buffer.
func (*Editor) SetPromptWidth ¶
SetPromptWidth sets the prompt width for cursor positioning.
func (*Editor) SetStreamingModel ¶
SetStreamingModel sets the model name for "Thinking..." display.
type EditorState ¶
EditorState holds the current editor state.
type GhostText ¶
type GhostText struct {
Text string // The full ghost text suggestion
AcceptedAt int // Number of characters already accepted (for partial acceptance)
Active bool // Whether ghost text is currently displayed
Streaming bool // Whether more text is still arriving
FromAgent bool // True for agent suggestions (show hints), false for predictions (fish-style)
}
GhostText represents inline suggestion text that appears after the cursor. Ghost text is shown in dim gray and can be accepted with Tab or dismissed with Esc.
func (*GhostText) AcceptAll ¶
AcceptAll accepts all remaining ghost text. Returns the text that should be inserted.
func (*GhostText) AcceptChar ¶
AcceptChar accepts the next character of ghost text. Returns the character that should be inserted.
func (*GhostText) AcceptWord ¶
AcceptWord accepts the next word of ghost text. Returns the text that should be inserted.
func (*GhostText) SetStreaming ¶
SetStreaming marks the ghost text as still receiving data.
type GhostTextChan ¶
type GhostTextChan <-chan string
GhostTextChan is a channel that receives ghost text updates.
type InputReader ¶
type InputReader struct {
// contains filtered or unexported fields
}
InputReader reads keys from a terminal.
func NewInputReader ¶
func NewInputReader(in io.Reader) *InputReader
NewInputReader creates a new input reader.
func (*InputReader) DrainPending ¶
func (r *InputReader) DrainPending()
DrainPending reads any immediately available input without blocking. This captures characters that may have been typed during terminal mode transitions. Call this right after enabling raw mode to recover any "lost" keystrokes.
func (*InputReader) ReadKey ¶
func (r *InputReader) ReadKey() (Key, error)
ReadKey reads and parses the next key.
func (*InputReader) ReadKeyInterruptible ¶
func (r *InputReader) ReadKeyInterruptible(done <-chan struct{}) (Key, error)
ReadKeyInterruptible reads and parses the next key, checking done channel periodically. If done is closed, returns context.Canceled error. This prevents goroutines from blocking indefinitely on stdin when the editor exits.
func (*InputReader) SetMaxPasteSize ¶ added in v0.4.3
func (r *InputReader) SetMaxPasteSize(size uint)
SetMaxPasteSize sets the maximum paste size in bytes.
type InsertMode ¶
type InsertMode struct{}
InsertMode is the default text entry mode.
func (*InsertMode) HandleKey ¶
func (m *InsertMode) HandleKey(key Key, state *EditorState) ModeResult
HandleKey processes a key in insert mode.
type Key ¶
type Key struct {
Rune rune
Special KeyCode
Ctrl bool
Alt bool
Shift bool
PasteText string // Content for KeyPaste (bracketed paste)
}
Key represents a parsed keypress.
type Mode ¶
type Mode interface {
Name() string
HandleKey(key Key, state *EditorState) ModeResult
}
Mode handles key input for a specific editing mode.
type ModeResult ¶
type ModeResult struct {
NewMode Mode // Nil means stay in current mode
Action Action
Submit bool // True = user wants to execute
Complete bool // True = trigger completion
Prefetch bool // True = trigger completion prefetch (background)
HistoryPrev bool // True = navigate to previous history
HistoryNext bool // True = navigate to next history
HistorySearch bool // True = launch history search (Ctrl+R)
ContextPicker bool // True = launch context picker (Ctrl+P)
Yank bool // True = yank selection to clipboard
Paste bool // True = paste from clipboard
PasteBefore bool // True = paste before cursor (P)
}
ModeResult is returned by mode key handlers.
type NormalMode ¶
type NormalMode struct{}
NormalMode handles Helix-style normal mode keybindings.
func (*NormalMode) HandleKey ¶
func (m *NormalMode) HandleKey(key Key, state *EditorState) ModeResult
HandleKey processes a key in normal mode.
type Position ¶
type Position struct {
Row, Col int
}
Position represents a row/column position in the buffer.
type Result ¶
type Result struct {
Text string
Canceled bool // Ctrl+C - interrupt
EOF bool // Ctrl+D - exit shell
HistorySearch bool // Ctrl+R - launch history search
ContextPicker bool // Ctrl+P - launch context picker
}
Result is returned when the editor exits.
type UndoStack ¶
type UndoStack struct {
// contains filtered or unexported fields
}
UndoStack manages undo/redo history.