Terminal
Category: Terminal
Source: terminal.dart
Enums
Key
Enumerates known special keys parsed from terminal input.
| Value | Description |
|---|---|
escape | |
enter | |
backspace | |
tab | |
shiftTab | |
up | |
down | |
left | |
right | |
home | |
end | |
pageUp | |
pageDown | |
delete | |
ctrlA | |
ctrlC | |
ctrlD | |
ctrlE | |
ctrlK | |
ctrlL | |
ctrlU | |
ctrlW | |
ctrlShiftC | |
unknown |
Classes
sealed TerminalEvent
Base class for all terminal input events.
KeyEvent
A recognised special-key press.
Constructor
KeyEvent(
this.key, {
this.ctrl = false,
this.alt = false,
this.shift = false,
this.charCode,
})Properties
| Property | Type | Description |
|---|---|---|
key | Key | |
ctrl | bool | |
alt | bool | |
shift | bool | |
charCode | int? |
Methods
String toString()
CharEvent
A printable character (may be multi-byte UTF-8).
Constructor
CharEvent(this.char, {this.alt = false})Properties
| Property | Type | Description |
|---|---|---|
char | String | |
alt | bool |
Methods
String toString()
ResizeEvent
The terminal was resized.
Constructor
ResizeEvent(this.cols, this.rows)Properties
| Property | Type | Description |
|---|---|---|
cols | int | |
rows | int |
Methods
String toString()
MouseEvent
A mouse event (if mouse reporting is enabled).
The SGR button byte encodes a lot at once: low bits hold the button number (or wheel direction), bits 2–4 hold the Shift/Alt/Ctrl modifier state, bit 5 marks motion reports (drag events emitted by ?1002), and bit 6 distinguishes wheel events. Convenience getters expose these without forcing every caller to do the bit twiddling.
Constructor
MouseEvent(this.x, this.y, this.button, {this.isDown = true})Properties
| Property | Type | Description |
|---|---|---|
x | int | |
y | int | |
button | int | |
isDown | bool | |
isScroll | bool get | Whether this is a scroll-wheel event (up or down). |
isScrollUp | bool get | Whether the scroll direction is upward. Only meaningful when [isScroll] is true. |
isMotion | bool get | Whether this report is a motion (drag) event under ?1002/?1003. When true, [isDown] also reads true on most terminals — the motion bit fires while a button is held. |
shift | bool get | SGR modifier bits. |
alt | bool get | |
ctrl | bool get | |
buttonNumber | int get | Button number with modifier/motion/wheel bits stripped. 0 = left, 1 = middle, 2 = right, 3 = release-untracked. |
isScroll | bool get | Whether this is a scroll-wheel event (up or down). |
isScrollUp | bool get | Whether the scroll direction is upward. Only meaningful when [isScroll] is true. |
isMotion | bool get | Whether this report is a motion (drag) event under ?1002/?1003. When true, [isDown] also reads true on most terminals — the motion bit fires while a button is held. |
shift | bool get | SGR modifier bits. |
alt | bool get | |
ctrl | bool get | |
buttonNumber | int get | Button number with modifier/motion/wheel bits stripped. 0 = left, 1 = middle, 2 = right, 3 = release-untracked. |
Methods
String toString()
PasteEvent
Bracketed paste content from the terminal.
Constructor
PasteEvent(this.content)Properties
| Property | Type | Description |
|---|---|---|
content | String |
Methods
String toString()
AnsiStyle
A pair of ANSI escape sequences that bracket styled text.
Constructor
const AnsiStyle(this.open, this.close)Properties
| Property | Type | Description |
|---|---|---|
open | String | |
close | String | |
bold | const | |
dim | const | |
italic | const | |
underline | const | |
inverse | const | |
red | const | |
green | const | |
yellow | const | |
blue | const | |
magenta | const | |
cyan | const | |
gray | const |
Terminal
Low-level terminal controller.
Takes over raw stdin/stdout, parses byte sequences into semantic [TerminalEvent]s, and exposes ANSI helpers for cursor movement, styling, and screen management.
Properties
| Property | Type | Description |
|---|---|---|
events | Stream<TerminalEvent> get | Stream of parsed terminal input events. |
columns | int get | Current terminal width in columns. |
rows | int get | Current terminal height in rows. |
isRaw | bool get | Whether the terminal is currently in raw mode. |
events | Stream<TerminalEvent> get | Stream of parsed terminal input events. |
columns | int get | Current terminal width in columns. |
rows | int get | Current terminal height in rows. |
isRaw | bool get | Whether the terminal is currently in raw mode. |
Methods
void enableRawMode()
Enters raw mode — the terminal now owns every byte from stdin.
void disableRawMode()
Restores normal terminal mode.
void dispose()
Releases all resources.
void write(String s)
Writes raw text to stdout.
void moveTo(int row, int col)
Moves the cursor to (1-indexed) [row], [col].
void clearScreen()
Clears the entire screen.
void clearLine()
Clears the current line.
void hideCursor()
Hides the cursor.
void showCursor()
Shows the cursor.
void saveCursor()
Saves the cursor position (DEC private).
void restoreCursor()
Restores the cursor position (DEC private).
void enableAltScreen()
Enters the alternate screen buffer.
void disableAltScreen()
Leaves the alternate screen buffer.
void enableMouse()
Enables mouse reporting: X10 button-press + SGR coordinates + ?1002 button-event tracking (motion while a button is held).
?1002 is required for drag-to-select. It does not enable arbitrary hover motion (that would be ?1003, which floods Terminal.app and tmux). Shift-drag is generally passed through by terminals as a native-selection escape hatch even with capture on, but consumers must also explicitly ignore Shift-modified motion events.
void disableMouse()
Disables mouse reporting (clear every mode enableMouse set).
void setScrollRegion(int top, int bottom)
Sets the hardware scroll region to rows [top] through [bottom] (1-indexed).
void resetScrollRegion()
Resets the scroll region to the full terminal height.
void writeStyled(String text, {AnsiStyle? style})
Writes [text] wrapped in the given ANSI [style].