AnsiOutput class

A utility class for formatting terminal output using ANSI colors and background styles.

This class provides static helper methods to apply foreground or background ANSI styles to any string, making console logs more readable and expressive.


βœ… Example Usage:

print(AnsiOutput.green("βœ” Success"));
print(AnsiOutput.red("βœ– Error"));
print(AnsiOutput.onRed("πŸ”₯ CRITICAL"));
print(AnsiOutput.onYellow("⚠ Warning", AnsiColor.BLACK));

You can also manually apply styles with:

print(AnsiOutput.apply(AnsiColor.BOLD, "Important!"));

Typically used in CLI tools, startup banners, or colored logging.

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 Methods

apply(AnsiColor color, String text) β†’ String
Applies a foreground color to the given text.
blue(String text) β†’ String
Foreground: bright blue.
cyan(String text) β†’ String
Foreground: bright cyan.
darkGreen(String text) β†’ String
Foreground: dark green.
darkRed(String text) β†’ String
Foreground: dark red.
gray(String text) β†’ String
Foreground: gray (mapped to white).
green(String text) β†’ String
Foreground: bright green.
magenta(String text) β†’ String
Foreground: bright magenta.
onBackground(AnsiColor background, String text, [AnsiColor? foreground]) β†’ String
Applies a background color and optional foreground to the given text.
onRed(String text, [AnsiColor fg = AnsiColor.WHITE]) β†’ String
Shorthand for white text on bright red background.
onYellow(String text, [AnsiColor fg = AnsiColor.BLACK]) β†’ String
Shorthand for black text on bright yellow background.
red(String text) β†’ String
Foreground: bright red.
white(String text) β†’ String
Foreground: bright white.
yellow(String text) β†’ String
Foreground: bright yellow.