LineEditor class

A raw-mode line editor with command-history navigation.

Reads bytes from input, echoes editing to output, and delivers each committed line to onLine. When interactive is true the terminal is put into raw mode (via setRawMode) so arrow keys and other control sequences are visible; the editor then implements its own line editing:

  • Enter commits the line.
  • Backspace / Delete edit around the cursor.
  • Left / Right / Home / End (and Ctrl-A / Ctrl-E) move the cursor.
  • Up / Down walk backward / forward through history; when text has been typed, navigation is restricted to entries starting with that prefix.
  • Ctrl-C discards the current line; Ctrl-D on an empty line signals EOF.

When interactive is false (piped input, no TTY) it degrades to plain line-buffered reading with no history navigation, preserving non-interactive use such as echo ':info' | omnyshell connect ....

When width (the terminal column count) is known, the editor repaints across every row a wrapped line occupies. When it is 0 (unknown) the editor falls back to a single-row repaint, which staircases a fresh prompt per keystroke once the prompt+input is wide enough to wrap — so hosts on a terminal that can report its width should pass it and keep it current via setWidth. (Display width is counted one column per rune, so double-width CJK / emoji in the line may still misalign.)

Constructors

LineEditor({required Stream<List<int>> input, required void output(String), required FutureOr<void> onLine(String line), required CommandHistoryStore history, bool interactive = true, int width = 0, void setRawMode(bool raw)?, void onInterrupt()?, void onEof()?, void onRaw(List<int> bytes)?, Future<List<String>> onComplete(String word, bool isCommand)?})

Properties

hashCode int
The hash code for this object.
no setterinherited
hasPendingPrompt bool
Whether a prompt is currently awaiting an answer (so a host can decide whether a Ctrl-C should unblock it).
no setter
interactive bool
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addHistory(String line) Future<void>
Records line in the history (subject to CommandHistoryStore.add rules) and resets the navigation cursor to the newest entry.
close() Future<void>
Stops reading and restores the terminal modes. Safe to call more than once.
hideIdlePrompt(bool hidden) → void
Hides or restores the persistent idle prompt. While hidden, the editor draws no prompt between commands (used so the AI agent owns the screen); an explicit prompt question still shows. The host repaints the prompt when restoring.
interrupt() → void
Handles a Ctrl-C that arrived out-of-band (raw mode keeps ISIG enabled, so the terminal raises SIGINT instead of delivering a 0x03 byte).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
printAbove(void emit()) → void
Emits output via emit without disturbing the current input line.
prompt(String text) Future<String>
Reads a single line of input after showing text, for a local command that needs an answer (e.g. a :download confirmation).
setPassthrough(bool on) → void
Enables or disables raw passthrough. While on, bytes from the input are forwarded verbatim to onRaw (bypassing line editing); the local edit buffer and any partial escape/UTF-8 state are reset on each transition.
setPrompt(String prompt) → void
Updates the prompt shown before the input and repaints the current line.
setWidth(int cols) → void
Updates the known terminal width (column count) and repaints, so wrapped lines reflow. Pass 0 when the width is unknown (single-row fallback).
start() → void
Begins reading input. In non-interactive mode this simply splits input into lines; in interactive mode it enables raw terminal handling.
suspendInput<R>(Future<R> body(Stream<List<int>> input)) Future<R>
Hands the input stream to body for the duration of a full-screen takeover (e.g. the :ide TUI), then resumes line editing.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited