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 ....

Note: the editor assumes the visible line fits on a single terminal row; inputs long enough to wrap may not repaint perfectly.

Constructors

LineEditor({required Stream<List<int>> input, required void output(String), required FutureOr<void> onLine(String line), required CommandHistory history, bool interactive = true, 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
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 CommandHistory.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.
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.
start() → void
Begins reading input. In non-interactive mode this simply splits input into lines; in interactive mode it enables raw terminal handling.
toString() String
A string representation of this object.
inherited

Operators

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