Ansi class abstract final Terminal

Unified ANSI escape sequence constants and utilities.

This module provides a single source of truth for all ANSI escape sequences used throughout the artisanal package, including both static components and the TUI runtime.

Artisanal includes a comprehensive Ansi utility class for generating standard ANSI escape sequences for colors, styles, cursor movement, and screen control.

For more advanced rendering, see the Ultraviolet subsystem. package:artisanal/uv.dart remains a compatibility re-export.

import 'package:artisanal/terminal.dart';

// Use constants
stdout.write(Ansi.cursorHide);
stdout.write(Ansi.clearScreen);

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

ansiPattern → RegExp
Pattern matching all ANSI escape sequences.
final

Static Methods

bg16(int color) → String
Sets background color using ANSI 16-color palette (0-15).
bg256(int color) → String
Sets background color using 256-color palette.
bgRgb(int r, int g, int b) → String
Sets background color using RGB true color.
consumeEscapeSequence(String text, int index) → int
If text contains an ANSI escape sequence starting at index, returns the index immediately after the sequence; otherwise returns index.
cursorDownBy(int n) → String
Moves cursor down by n lines.
cursorLeftBy(int n) → String
Moves cursor left by n columns.
cursorNextLineBy(int n) → String
Moves cursor to beginning of line n lines down.
cursorPosition(int row, int col) → String
Alias for cursorTo using 'f' terminator.
cursorPrevLineBy(int n) → String
Moves cursor to beginning of line n lines up.
cursorRightBy(int n) → String
Moves cursor right by n columns.
cursorTo(int row, int col) → String
Moves cursor to row and col (1-based).
cursorToColumn(int n) → String
Moves cursor to column n (1-based).
cursorUpBy(int n) → String
Moves cursor up by n lines.
cut(String text, int start, int end) → String
Cuts a string at given character indices, preserving ANSI state.
expandTabs(String text, {int tabWidth = defaultTabWidth}) → String
Expands tab characters (\t) to spaces.
fg16(int color) → String
Sets foreground color using ANSI 16-color palette (0-15).
fg256(int color) → String
Sets foreground color using 256-color palette.
fgRgb(int r, int g, int b) → String
Sets foreground color using RGB true color.
kittyKeyboard(int flags, {int mode = 0}) → String
Sets the Kitty keyboard protocol flags.
requestTermcapStrings(Iterable<String> names) → String
Requests termcap/terminfo capability strings (XTGETTCAP).
scrollDownBy(int n) → String
Scrolls screen down by n lines.
scrollUpBy(int n) → String
Scrolls screen up by n lines.
setProgressBar(int state, int value) → String
Sets the terminal progress bar (OSC 9;4).
setScrollRegion(int top, int bottom) → String
Sets the vertical scrolling region using DECSTBM.
setTitle(String title) → String
Sets the window title. Use with bel to terminate.
stripAnsi(String text) → String
Strips all ANSI escape sequences from a string.
truncateLeft(String text, int n, [String replacement = '']) → String
Truncates a string from the left by n characters, preserving ANSI state.
visibleLength(String text) → int
Calculates the visible width of a string (excluding ANSI sequences).
wrap(String text, String startSeq, String endSeq) → String
Wraps text in ANSI sequences that will be stripped by stripAnsi.

Constants

altScreenEnter → const String
Enters the alternate screen buffer (fullscreen mode).
altScreenExit → const String
Exits the alternate screen buffer.
apc → const String
The Application Program Command introducer (ESC _).
beginSynchronizedUpdate → const String
Begin Synchronized Update — tells the terminal to buffer all output.
bel → const String
The Bell character (BEL, 0x07).
bell → const String
Rings the terminal bell.
bgDefault → const String
Resets background color to default.
Enables slow blink mode.
blinkOff → const String
Disables blink mode.
bold → const String
Enables bold/bright mode.
boldOff → const String
Disables bold mode.
bracketedPasteDisable → const String
Disables bracketed paste mode.
bracketedPasteEnable → const String
Enables bracketed paste mode.
bracketedPasteEnd → const String
End of bracketed paste content.
bracketedPasteStart → const String
Start of bracketed paste content.
clearLine → const String
Clears the entire current line.
clearLineToEnd → const String
Clears from cursor to end of line.
clearLineToEndExplicit → const String
Clears from cursor to end of line (explicit mode).
clearLineToStart → const String
Clears from cursor to beginning of line.
clearScreen → const String
Clears the entire screen.
clearScreenAndScrollback → const String
Clears entire screen and scrollback buffer.
clearScreenToEnd → const String
Clears from cursor to end of screen.
clearScreenToEndExplicit → const String
Clears from cursor to end of screen (explicit mode).
clearScreenToStart → const String
Clears from cursor to beginning of screen.
csi → const String
The Control Sequence Introducer (ESC [).
cursorDown → const String
Moves cursor down one line.
cursorHide → const String
Hides the cursor.
cursorHome → const String
Moves cursor to home position (1, 1).
cursorLeft → const String
Moves cursor left one column.
cursorNextLine → const String
Moves cursor to beginning of next line.
cursorPrevLine → const String
Moves cursor to beginning of previous line.
cursorRestore → const String
Restores the previously saved cursor position (ANSI.SYS).
cursorRestoreDec → const String
Restores cursor position (DEC private mode).
cursorRight → const String
Moves cursor right one column.
cursorSave → const String
Saves the current cursor position (ANSI.SYS).
cursorSaveDec → const String
Saves cursor position (DEC private mode).
cursorShow → const String
Shows the cursor.
cursorUp → const String
Moves cursor up one line.
defaultTabWidth → const int
Default tab width used by our string renderers when expanding \t.
dim → const String
Enables dim/faint mode.
endSynchronizedUpdate → const String
End Synchronized Update — tells the terminal to flush buffered output.
escape → const String
The escape character (ESC, 0x1B).
fgDefault → const String
Resets foreground color to default.
focusDisable → const String
Disables focus reporting.
focusEnable → const String
Enables focus reporting.
focusIn → const String
Focus gained sequence.
focusOut → const String
Focus lost sequence.
hidden → const String
Enables hidden/invisible mode.
hiddenOff → const String
Disables hidden mode.
italic → const String
Enables italic mode.
italicOff → const String
Disables italic mode.
kittyDisambiguateEscapeCodes → const int
Kitty keyboard protocol flags.
kittyReportAllKeysAsEscapeCodes → const int
kittyReportAlternateKeys → const int
kittyReportAssociatedText → const int
kittyReportEventTypes → const int
lineDrawingDisable → const String
Disables line drawing character set (return to ASCII).
lineDrawingEnable → const String
Enables line drawing character set.
mouseDisableAny → const String
Disables any-event tracking.
mouseDisableButton → const String
Disables button event tracking.
mouseDisableNormal → const String
Disables normal mouse tracking.
mouseDisableSgr → const String
Disables SGR extended mouse mode.
mouseDisableUtf8 → const String
Disables UTF-8 mouse mode.
mouseDisableX10 → const String
Disables X10 mouse reporting.
mouseEnableAny → const String
Enables any-event tracking (all motion events).
mouseEnableButton → const String
Enables button event tracking (press, release, motion with button).
mouseEnableNormal → const String
Enables normal mouse tracking (button press and release).
mouseEnableSgr → const String
Enables SGR extended mouse mode (supports coordinates > 223).
mouseEnableUtf8 → const String
Enables UTF-8 mouse mode.
mouseEnableX10 → const String
Enables X10 mouse reporting (button press only).
nbsp → const String
Non-breaking space (NBSP, U+00A0).
normalIntensity → const String
Disables bold and dim modes.
osc → const String
The Operating System Command introducer (ESC ]).
Enables rapid blink mode.
requestBackgroundColor → const String
Requests the terminal background color (OSC 11).
requestColorScheme → const String
Requests the terminal light/dark color-scheme preference.
requestCursorColor → const String
Requests the terminal cursor color (OSC 12).
requestCursorPosition → const String
Requests cursor position report. Terminal responds with \x1b[{row};{col}R.
requestDeviceAttributes → const String
Requests device attributes.
requestExtendedCursorPosition → const String
Requests extended cursor position report (DECXCPR).
requestForegroundColor → const String
Requests the terminal foreground color (OSC 10).
requestKittyKeyboard → const String
Requests the current Kitty keyboard protocol flags.
requestModifyOtherKeys → const String
Requests the xterm ModifyOtherKeys mode.
requestPrimaryDeviceAttributes → const String
Request primary device attributes (DA1).
requestSecondaryDeviceAttributes → const String
Request secondary device attributes (DA2).
requestTerminalVersion → const String
Request xterm name and version (XTVERSION).
requestTertiaryDeviceAttributes → const String
Request tertiary device attributes (DA3).
reset → const String
Resets all attributes to default.
resetKittyKeyboard → const String
Resets the Kitty keyboard protocol flags to 0.
resetProgressBar → const String
Resets the terminal progress bar (OSC 9;4).
resetScrollRegion → const String
Resets the vertical scrolling region to the full terminal.
reverse → const String
Enables reverse/inverse mode.
reverseOff → const String
Disables reverse mode.
scrollDown → const String
Scrolls screen down by one line.
scrollUp → const String
Scrolls screen up by one line.
st → const String
The String Terminator (ESC ).
strikethrough → const String
Enables strikethrough mode.
strikethroughOff → const String
Disables strikethrough mode.
underline → const String
Enables underline mode.
underlineOff → const String
Disables underline mode.