AnsiPen class
A fluent pen-style API for building ANSI-styled strings.
Drop-in replacement for the ansicolor package's AnsiPen, with
additional styles (bold, italic, strikethrough, etc.), 16M true color RGB,
and correct nested color handling.
final pen = AnsiPen()..red();
print(pen('Hello'));
final fancy = AnsiPen().red().bold.italic;
print(fancy('Fancy text'));
Properties
- bgBlack → AnsiPen
-
Sets background color to black.
no setter
- bgBlue → AnsiPen
-
Sets background color to blue.
no setter
- bgBlueBright → AnsiPen
-
Sets background color to bright blue.
no setter
- bgCyan → AnsiPen
-
Sets background color to cyan.
no setter
- bgCyanBright → AnsiPen
-
Sets background color to bright cyan.
no setter
- bgGray → AnsiPen
-
Sets background color to gray (bright black).
no setter
- bgGreen → AnsiPen
-
Sets background color to green.
no setter
- bgGreenBright → AnsiPen
-
Sets background color to bright green.
no setter
- bgMagenta → AnsiPen
-
Sets background color to magenta.
no setter
- bgMagentaBright → AnsiPen
-
Sets background color to bright magenta.
no setter
- bgRed → AnsiPen
-
Sets background color to red.
no setter
- bgRedBright → AnsiPen
-
Sets background color to bright red.
no setter
- bgWhite → AnsiPen
-
Sets background color to white.
no setter
- bgWhiteBright → AnsiPen
-
Sets background color to bright white.
no setter
- bgYellow → AnsiPen
-
Sets background color to yellow.
no setter
- bgYellowBright → AnsiPen
-
Sets background color to bright yellow.
no setter
- blueBright → AnsiPen
-
Sets foreground color to bright blue.
no setter
- bold → AnsiPen
-
Adds bold style (SGR 1).
no setter
- cyanBright → AnsiPen
-
Sets foreground color to bright cyan.
no setter
- dim → AnsiPen
-
Adds dim/faint style (SGR 2).
no setter
- down → String
-
Returns the ANSI escape codes that open the pen's current styles.
Compatible with ansicolor's
pen.down/'${pen}'usage.no setter - greenBright → AnsiPen
-
Sets foreground color to bright green.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
Adds hidden/conceal style (SGR 8).
no setter
- inverse → AnsiPen
-
Adds inverse/reverse video style (SGR 7).
no setter
- italic → AnsiPen
-
Adds italic style (SGR 3).
no setter
- magentaBright → AnsiPen
-
Sets foreground color to bright magenta.
no setter
- overline → AnsiPen
-
Adds overline style (SGR 53).
no setter
- redBright → AnsiPen
-
Sets foreground color to bright red.
no setter
- reset → AnsiPen
-
Adds a reset style (SGR 0) to the pen.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strikethrough → AnsiPen
-
Adds strikethrough style (SGR 9).
no setter
-
styleStack
↔ List<
QuectoStyler> -
The stack of QuectoStyler closures applied by this pen.
getter/setter pair
- underline → AnsiPen
-
Adds underline style (SGR 4).
no setter
- up → String
-
Resets all pen attributes in the terminal.
Compatible with ansicolor's
pen.upusage.no setter - whiteBright → AnsiPen
-
Sets foreground color to bright white.
no setter
- yellowBright → AnsiPen
-
Sets foreground color to bright yellow.
no setter
Methods
-
ansi256Bg(
int code) → AnsiPen -
Sets background to xterm 256-color palette index
code(0–255). -
ansi256Fg(
int code) → AnsiPen -
Sets foreground to xterm 256-color palette index
code(0–255). -
black(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets black foreground (or background with
bg: true, bright withbold: true). -
blue(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets blue foreground (or background with
bg: true, bright withbold: true). -
call(
Object msg) → String -
Applies this pen's styles to
inputand returns the styled string. -
cyan(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets cyan foreground (or background with
bg: true, bright withbold: true). -
gray(
{num? level, bool bg = false}) → AnsiPen -
Set foreground to ANSI gray when called with no args (
pen.gray), or set to a xterm256 grayscale value when called withlevel:(compatible with ansicolor's AnsiPen.gray() signature). -
green(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets green foreground (or background with
bg: true, bright withbold: true). -
grey(
{num? level, bool bg = false}) → AnsiPen - Alternate spelling for gray.
-
magenta(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets magenta foreground (or background with
bg: true, bright withbold: true). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
red(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets red foreground (or background with
bg: true, bright withbold: true). -
rgb(
{num r = 1.0, num g = 1.0, num b = 1.0, bool bg = false}) → AnsiPen - Sets the pen color to the rgb value between 0.0..1.0. Compatible with ansicolor's AnsiPen.rgb() signature. Maps to xterm 256-color palette (same as ansicolor).
-
rgbBg(
int r, int g, int b) → AnsiPen - Sets background to 24-bit true color RGB.
-
rgbFg(
int r, int g, int b) → AnsiPen - Sets foreground to 24-bit true color RGB.
-
toString(
) → String -
Allow pen colors to be used inline:
'${pen}text${pen.up}'. Compatible with ansicolor's toString() behavior.override -
underlineAnsi256(
int code) → AnsiPen -
Sets underline color to xterm 256-color palette index
code(0–255). -
underlineRgb(
int r, int g, int b) → AnsiPen - Sets underline color to 24-bit true color RGB.
-
white(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets white foreground (or background with
bg: true, bright withbold: true). -
write(
Object msg) → String -
Applies this pen's styles to
inputand returns the styled string. -
xterm(
int color, {bool bg = false}) → AnsiPen - Directly index the xterm 256 color palette. Compatible with ansicolor's AnsiPen.xterm() signature.
-
yellow(
{bool bg = false, bool bold = false}) → AnsiPen -
Sets yellow foreground (or background with
bg: true, bright withbold: true).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited