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 giventext
. -
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 optionalforeground
to the giventext
. -
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.