Skip to content

Terminal

Category: Terminal

Source: terminal.dart

Enums

Key

Enumerates known special keys parsed from terminal input.

ValueDescription
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

dart
KeyEvent(
    this.key, {
    this.ctrl = false,
    this.alt = false,
    this.shift = false,
    this.charCode,
  })

Properties

PropertyTypeDescription
keyKey
ctrlbool
altbool
shiftbool
charCodeint?

Methods

String toString()

CharEvent

A printable character (may be multi-byte UTF-8).

Constructor

dart
CharEvent(this.char, {this.alt = false})

Properties

PropertyTypeDescription
charString
altbool

Methods

String toString()

ResizeEvent

The terminal was resized.

Constructor

dart
ResizeEvent(this.cols, this.rows)

Properties

PropertyTypeDescription
colsint
rowsint

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

dart
MouseEvent(this.x, this.y, this.button, {this.isDown = true})

Properties

PropertyTypeDescription
xint
yint
buttonint
isDownbool
isScrollbool getWhether this is a scroll-wheel event (up or down).
isScrollUpbool getWhether the scroll direction is upward. Only meaningful when [isScroll] is true.
isMotionbool getWhether 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.
shiftbool getSGR modifier bits.
altbool get
ctrlbool get
buttonNumberint getButton number with modifier/motion/wheel bits stripped. 0 = left, 1 = middle, 2 = right, 3 = release-untracked.
isScrollbool getWhether this is a scroll-wheel event (up or down).
isScrollUpbool getWhether the scroll direction is upward. Only meaningful when [isScroll] is true.
isMotionbool getWhether 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.
shiftbool getSGR modifier bits.
altbool get
ctrlbool get
buttonNumberint getButton 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

dart
PasteEvent(this.content)

Properties

PropertyTypeDescription
contentString

Methods

String toString()

AnsiStyle

A pair of ANSI escape sequences that bracket styled text.

Constructor

dart
const AnsiStyle(this.open, this.close)

Properties

PropertyTypeDescription
openString
closeString
boldconst
dimconst
italicconst
underlineconst
inverseconst
redconst
greenconst
yellowconst
blueconst
magentaconst
cyanconst
grayconst

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

PropertyTypeDescription
eventsStream<TerminalEvent> getStream of parsed terminal input events.
columnsint getCurrent terminal width in columns.
rowsint getCurrent terminal height in rows.
isRawbool getWhether the terminal is currently in raw mode.
eventsStream<TerminalEvent> getStream of parsed terminal input events.
columnsint getCurrent terminal width in columns.
rowsint getCurrent terminal height in rows.
isRawbool getWhether 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].

Released under the MIT License.