PrivatebufferPrivatecursorPrivatemaxPrivatepromptPrivateterminalDeletes the character before the cursor (backspace operation).
VT100 escape sequences to update the terminal display, or empty string if at start
Clears the buffer and resets cursor to position 0.
Clears the entire line and resets buffer (Ctrl+U).
VT100 escape sequences to clear the terminal line
Clears from cursor position to end of line (Ctrl+K).
VT100 escape sequence to clear the terminal
Deletes the character at the cursor position (delete key operation).
VT100 escape sequences to update the terminal display, or empty string if at end
Returns the current buffer content.
The full text content of the buffer
Returns the current cursor position within the buffer.
The zero-based cursor position
Get the current cursor position as row/col.
Object with row (0-based) and col (0-based) position
Get the end position (after the last character).
Object with row (0-based) and col (0-based) position
Returns the maximum buffer size.
The maximum size in bytes
Calculate the row and column position for a given buffer offset. Takes into account the prompt length on the first line.
The buffer offset (0-based)
Object with row (0-based) and col (0-based) position
Get the current prompt length.
The prompt length in characters
Calculate the number of rows the current content spans.
The total number of rows (1-based)
Get the current terminal width.
The terminal width in columns
Returns the word immediately before the cursor for auto-completion.
A word is defined as a sequence of word characters (\w) and dots.
The word before cursor, or empty string if none
Inserts text at the cursor position.
The character(s) to insert
VT100 escape sequences to update the terminal display
Checks if the buffer contains only whitespace.
True if buffer is empty or contains only whitespace
Checks if the buffer is empty.
True if buffer has no content
PrivatemoveGenerate VT100 escape sequence to move from one position to another.
The starting position
The target position
VT100 escape sequence string
Moves the cursor one position to the left.
VT100 escape sequence, or empty string if already at start
Moves the cursor one position to the right.
VT100 escape sequence, or empty string if already at end
Moves the cursor to the end of the line (End key / Ctrl+E).
VT100 escape sequence, or empty string if already at end
Moves the cursor to the start of the line (Home key / Ctrl+A).
VT100 escape sequence, or empty string if already at start
Replaces the word before the cursor with a completion string.
The completion string to insert
VT100 escape sequences to update the terminal display
Sets the buffer content and moves cursor to end.
Used for history navigation when replacing the current line with a previous command.
The new buffer content
Sets the maximum buffer size.
Maximum size in bytes (defaults to MAX_BUFFER_SIZE)
Set the prompt length for cursor calculations. This is needed to correctly calculate line wrapping since the prompt takes up space on the first line.
The visible length of the prompt (excluding ANSI codes)
Set the terminal width for line wrapping calculations.
The terminal width in columns
A text buffer with cursor management for terminal line editing.
The InputBuffer maintains both the current text content and cursor position, providing methods for common editing operations. Each editing method returns the VT100 escape sequences needed to update the terminal display.
Features:
Example: Basic usage
Example: Cursor movement
Example: Auto-completion