Class ANSIBuilder
Basic usage:
String output = ANSIBuilder.builder()
.bold().redText("Error: ").boldOff()
.append("Something went wrong")
.toString();
Theme-aware usage with semantic colors:
TerminalColorCapability cap = TerminalColorCapability.detectFromEnvironment();
String output = ANSIBuilder.builder(cap)
.timestamp("2024-01-15 10:30:45").append(" ")
.error("ERROR").append(" ")
.category("[org.aesh.readline.ReadlineConsole]").append(" ")
.threadName("(main)").append(" ")
.message("Failed to initialize readline")
.toString();
Extended color support:
ANSIBuilder.builder()
.bright().redText("Bright red") // Bright color variant
.color256(208).append("Orange") // 256-color palette
.rgb(255, 100, 50).append("Custom") // True color RGB
.toString();
- Author:
- Ståle Pedersen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of ANSI color codes for text and background colors.static enumEnumeration of ANSI text style/type codes. -
Method Summary
Modifier and TypeMethodDescriptionappend(char data) Appends a character to the builder.append(char[] data) Appends a character array to the builder.append(double data) Appends a double to the builder.append(float data) Appends a float to the builder.append(int data) Appends an integer to the builder.append(long data) Appends a long to the builder.append(CharSequence data) Appends a CharSequence to the builder.Appends an Object to the builder.Appends a string to the builder.append(StringBuilder data) Appends a StringBuilder to the builder.appendLine(String text) Appends text followed by a newline.bg(ANSIBuilder.Color color) Sets the background color.bg256(int index) Sets the background color using the 256-color palette.Appends text with the specified 256-color background and resets.bgCode(int code) Sets the background color using a raw ANSI color code.Sets the background color using a hex color value.bgHsl(float h, float s, float l) Sets the background color using HSL values (converted to RGB true color).Appends text with the specified HSL background color and resets.bgRgb(int r, int g, int b) Sets the background color using RGB values (true color).blackBg()Sets background color to black.Appends text with black background and resets.Sets foreground text color to black.Appends text with black foreground color and resets.blink()Enables blinking text style.Appends text with blink style and disables blink after.blinkOff()Disables blinking text style.blueBg()Sets background color to blue.Appends text with blue background and resets.blueText()Sets foreground text color to blue.Appends text with blue foreground color and resets.bold()Enables bold text style.Appends text with bold style and disables bold after.boldOff()Disables bold text style.bright()Enables bright (high intensity) mode for subsequent colors.Disables bright mode, returning to normal intensity colors.static ANSIBuilderbuilder()Creates a new ANSIBuilder with ANSI formatting enabled.static ANSIBuilderbuilder(boolean enableAnsi) Creates a new ANSIBuilder with configurable ANSI formatting.static ANSIBuilderbuilder(TerminalColorCapability capability) Creates a new theme-aware ANSIBuilder with terminal color capability.category()Sets the foreground color to the theme-appropriate category color (blue).Appends text with category styling (blue) and resets.categoryCode(int code) Overrides the category (package/class name) color code for this builder.categoryHex(String hex) Overrides the category color using a hex color value.categoryHsl(float h, float s, float l) Overrides the category color using HSL values.categoryRgb(int r, int g, int b) Overrides the category color using RGB values (true color).clear()Clears the builder content and resets all formatting.color256(int index) Sets the foreground color using the 256-color palette.Appends text with the specified 256-color foreground and resets.conceal()Enables concealed (hidden) text style.Appends text with concealed style and disables conceal after.Disables concealed text style.Enables crossed-out (strikethrough) text style.crossedOut(String text) Appends text with crossed-out style and disables it after.Disables crossed-out text style.cyanBg()Sets background color to cyan.Appends text with cyan background and resets.cyanText()Sets foreground text color to cyan.Appends text with cyan foreground color and resets.debug()Sets the foreground color to the theme-appropriate debug color (cyan).Appends text with debug styling and resets.debugCode(int code) Overrides the debug color code for this builder.Overrides the debug color using a hex color value.debugHsl(float h, float s, float l) Overrides the debug color using HSL values.debugRgb(int r, int g, int b) Overrides the debug color using RGB values (true color).Sets background color to default.Appends text with default background and resets.Sets foreground text color to default.defaultText(String text) Appends text with default foreground color and resets.error()Sets the foreground color to the theme-appropriate error color (red).Appends text with error styling (red) and resets.errorCode(int code) Overrides the error color code for this builder.Overrides the error color using a hex color value.errorHsl(float h, float s, float l) Overrides the error color using HSL values.errorRgb(int r, int g, int b) Overrides the error color using RGB values (true color).faint()Enables faint (dim) text style.Appends text with faint style and resets after.faintOff()Disables faint text style.fatal()Sets the foreground color to the theme-appropriate fatal color (red).Appends text with fatal styling (red) and resets.fatalCode(int code) Overrides the fatal color code for this builder.Overrides the fatal color using a hex color value.fatalHsl(float h, float s, float l) Overrides the fatal color using HSL values.fatalRgb(int r, int g, int b) Overrides the fatal color using RGB values (true color).greenBg()Sets background color to green.Appends text with green background and resets.Sets foreground text color to green.Appends text with green foreground color and resets.Sets the foreground color using a hex color value.Appends text with the specified hex foreground color and resets.hsl(float h, float s, float l) Sets the foreground color using HSL values (converted to RGB true color).Appends text with the specified HSL foreground color and resets.info()Sets the foreground color to the theme-appropriate info color (green).Appends text with info styling (green) and resets.infoCode(int code) Overrides the info color code for this builder.Overrides the info color using a hex color value.infoHsl(float h, float s, float l) Overrides the info color using HSL values.infoRgb(int r, int g, int b) Overrides the info color using RGB values (true color).invert()Enables inverted (reverse video) text style.Appends text with inverted style and disables invert after.Disables inverted text style.italic()Enables italic text style.Appends text with italic style and disables italic after.Disables italic text style.Sets background color to magenta.Appends text with magenta background and resets.Sets foreground text color to magenta.magentaText(String text) Appends text with magenta foreground color and resets.message()Sets the foreground color to the theme-appropriate message color (magenta).Appends text with message styling (magenta) and resets.messageCode(int code) Overrides the message color code for this builder.messageHex(String hex) Overrides the message color using a hex color value.messageHsl(float h, float s, float l) Overrides the message color using HSL values.messageRgb(int r, int g, int b) Overrides the message color using RGB values (true color).newline()Appends a newline to the builder.redBg()Sets background color to red.Appends text with red background and resets.redText()Sets foreground text color to red.Appends text with red foreground color and resets.reset()Clears the builder content and resets all formatting, identical to clear()Resets all colors and text styles to default.rgb(int r, int g, int b) Sets the foreground color using RGB values (true color).Appends text with the specified RGB foreground color and resets.success()Sets the foreground color to the theme-appropriate success color (green).Appends text with success styling (green) and resets.successCode(int code) Overrides the success color code for this builder.successHex(String hex) Overrides the success color using a hex color value.successHsl(float h, float s, float l) Overrides the success color using HSL values.successRgb(int r, int g, int b) Overrides the success color using RGB values (true color).text(ANSIBuilder.Color color) Sets the foreground text color.textCode(int code) Sets the foreground color using a raw ANSI color code.textType(ANSIBuilder.TextType type) Sets the text type/style.Sets the foreground color to the theme-appropriate thread name color (green).threadName(String text) Appends text with thread name styling (green) and resets.threadNameCode(int code) Overrides the thread name color code for this builder.threadNameHex(String hex) Overrides the thread name color using a hex color value.threadNameHsl(float h, float s, float l) Overrides the thread name color using HSL values.threadNameRgb(int r, int g, int b) Overrides the thread name color using RGB values (true color).Sets the foreground color to the theme-appropriate timestamp color (gray).Appends text with timestamp styling (gray) and resets.timestampCode(int code) Overrides the timestamp color code for this builder.timestampHex(String hex) Overrides the timestamp color using a hex color value.timestampHsl(float h, float s, float l) Overrides the timestamp color using HSL values.timestampRgb(int r, int g, int b) Overrides the timestamp color using RGB values (true color).toLine()Returns the built string with ANSI formatting followed by a newline.toString()Returns the built string with ANSI formatting.trace()Sets the foreground color to the theme-appropriate trace color.Appends text with trace styling and resets.traceCode(int code) Overrides the trace color code for this builder.Overrides the trace color using a hex color value.traceHsl(float h, float s, float l) Overrides the trace color using HSL values.traceRgb(int r, int g, int b) Overrides the trace color using RGB values (true color).Enables underline text style.Appends text with underline style and disables underline after.Disables underline text style.warning()Sets the foreground color to the theme-appropriate warning color (yellow).Appends text with warning styling (yellow) and resets.warningCode(int code) Overrides the warning color code for this builder.warningHex(String hex) Overrides the warning color using a hex color value.warningHsl(float h, float s, float l) Overrides the warning color using HSL values.warningRgb(int r, int g, int b) Overrides the warning color using RGB values (true color).whiteBg()Sets background color to white.Appends text with white background and resets.Sets foreground text color to white.Appends text with white foreground color and resets.yellowBg()Sets background color to yellow.Appends text with yellow background and resets.Sets foreground text color to yellow.yellowText(String text) Appends text with yellow foreground color and resets.
-
Method Details
-
builder
Creates a new ANSIBuilder with ANSI formatting enabled.- Returns:
- a new ANSIBuilder instance
-
builder
Creates a new ANSIBuilder with configurable ANSI formatting.- Parameters:
enableAnsi- true to enable ANSI escape sequences, false to disable- Returns:
- a new ANSIBuilder instance
-
builder
Creates a new theme-aware ANSIBuilder with terminal color capability.When a capability is provided, semantic color methods like
error(),success(),timestamp(), etc. will automatically choose appropriate color intensities based on the terminal's theme (light or dark).- Parameters:
capability- the detected terminal color capability- Returns:
- a new ANSIBuilder instance configured for the terminal
-
errorCode
Overrides the error color code for this builder.This takes precedence over the capability-provided color. Supports basic ANSI codes (30-37, 90-97) or 256-color palette indices (0-255).
- Parameters:
code- the ANSI color code to use for error messages- Returns:
- this builder for method chaining
-
successCode
Overrides the success color code for this builder.- Parameters:
code- the ANSI color code to use for success messages- Returns:
- this builder for method chaining
-
warningCode
Overrides the warning color code for this builder.- Parameters:
code- the ANSI color code to use for warning messages- Returns:
- this builder for method chaining
-
infoCode
Overrides the info color code for this builder.- Parameters:
code- the ANSI color code to use for info messages- Returns:
- this builder for method chaining
-
debugCode
Overrides the debug color code for this builder.- Parameters:
code- the ANSI color code to use for debug messages- Returns:
- this builder for method chaining
-
traceCode
Overrides the trace color code for this builder.- Parameters:
code- the ANSI color code to use for trace messages- Returns:
- this builder for method chaining
-
timestampCode
Overrides the timestamp color code for this builder.- Parameters:
code- the ANSI color code to use for timestamps- Returns:
- this builder for method chaining
-
messageCode
Overrides the message color code for this builder.- Parameters:
code- the ANSI color code to use for highlighted messages- Returns:
- this builder for method chaining
-
categoryCode
Overrides the category (package/class name) color code for this builder.- Parameters:
code- the ANSI color code to use for category/logger names- Returns:
- this builder for method chaining
-
threadNameCode
Overrides the thread name color code for this builder.- Parameters:
code- the ANSI color code to use for thread names- Returns:
- this builder for method chaining
-
fatalCode
Overrides the fatal color code for this builder.- Parameters:
code- the ANSI color code to use for fatal messages- Returns:
- this builder for method chaining
-
errorRgb
Overrides the error color using RGB values (true color).RGB overrides take precedence over code overrides.
- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
errorHex
Overrides the error color using a hex color value.- Parameters:
hex- the color in hex format (e.g., "#FF5733" or "FF5733")- Returns:
- this builder for method chaining
-
errorHsl
Overrides the error color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
successRgb
Overrides the success color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
successHex
Overrides the success color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
successHsl
Overrides the success color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
warningRgb
Overrides the warning color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
warningHex
Overrides the warning color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
warningHsl
Overrides the warning color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
infoRgb
Overrides the info color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
infoHex
Overrides the info color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
infoHsl
Overrides the info color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
debugRgb
Overrides the debug color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
debugHex
Overrides the debug color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
debugHsl
Overrides the debug color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
traceRgb
Overrides the trace color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
traceHex
Overrides the trace color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
traceHsl
Overrides the trace color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
timestampRgb
Overrides the timestamp color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
timestampHex
Overrides the timestamp color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
timestampHsl
Overrides the timestamp color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
messageRgb
Overrides the message color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
messageHex
Overrides the message color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
messageHsl
Overrides the message color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
categoryRgb
Overrides the category color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
categoryHex
Overrides the category color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
categoryHsl
Overrides the category color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
threadNameRgb
Overrides the thread name color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
threadNameHex
Overrides the thread name color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
threadNameHsl
Overrides the thread name color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
fatalRgb
Overrides the fatal color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
-
fatalHex
Overrides the fatal color using a hex color value.- Parameters:
hex- the color in hex format- Returns:
- this builder for method chaining
-
fatalHsl
Overrides the fatal color using HSL values.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
resetColors
Resets all colors and text styles to default.- Returns:
- this builder for method chaining
-
clear
Clears the builder content and resets all formatting.- Returns:
- this builder for method chaining
-
reset
Clears the builder content and resets all formatting, identical to clear()- Returns:
- this builder for method chaining
-
text
Sets the foreground text color.- Parameters:
color- the color to use for text- Returns:
- this builder for method chaining
-
textType
Sets the text type/style.- Parameters:
type- the text type to apply- Returns:
- this builder for method chaining
-
bg
Sets the background color.- Parameters:
color- the color to use for background- Returns:
- this builder for method chaining
-
blackText
Sets foreground text color to black.- Returns:
- this builder for method chaining
-
redText
Sets foreground text color to red.- Returns:
- this builder for method chaining
-
greenText
Sets foreground text color to green.- Returns:
- this builder for method chaining
-
yellowText
Sets foreground text color to yellow.- Returns:
- this builder for method chaining
-
blueText
Sets foreground text color to blue.- Returns:
- this builder for method chaining
-
magentaText
Sets foreground text color to magenta.- Returns:
- this builder for method chaining
-
cyanText
Sets foreground text color to cyan.- Returns:
- this builder for method chaining
-
whiteText
Sets foreground text color to white.- Returns:
- this builder for method chaining
-
defaultText
Sets foreground text color to default.- Returns:
- this builder for method chaining
-
blackBg
Sets background color to black.- Returns:
- this builder for method chaining
-
redBg
Sets background color to red.- Returns:
- this builder for method chaining
-
greenBg
Sets background color to green.- Returns:
- this builder for method chaining
-
yellowBg
Sets background color to yellow.- Returns:
- this builder for method chaining
-
blueBg
Sets background color to blue.- Returns:
- this builder for method chaining
-
magentaBg
Sets background color to magenta.- Returns:
- this builder for method chaining
-
cyanBg
Sets background color to cyan.- Returns:
- this builder for method chaining
-
whiteBg
Sets background color to white.- Returns:
- this builder for method chaining
-
defaultBg
Sets background color to default.- Returns:
- this builder for method chaining
-
blackText
Appends text with black foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
redText
Appends text with red foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
greenText
Appends text with green foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
yellowText
Appends text with yellow foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
blueText
Appends text with blue foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
magentaText
Appends text with magenta foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
cyanText
Appends text with cyan foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
whiteText
Appends text with white foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
defaultText
Appends text with default foreground color and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
blackBg
Appends text with black background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
redBg
Appends text with red background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
greenBg
Appends text with green background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
yellowBg
Appends text with yellow background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
blueBg
Appends text with blue background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
magentaBg
Appends text with magenta background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
cyanBg
Appends text with cyan background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
whiteBg
Appends text with white background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
defaultBg
Appends text with default background and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
append
Appends a string to the builder.- Parameters:
data- the string to append- Returns:
- this builder for method chaining
-
append
Appends an integer to the builder.- Parameters:
data- the integer to append- Returns:
- this builder for method chaining
-
append
Appends a character to the builder.- Parameters:
data- the character to append- Returns:
- this builder for method chaining
-
append
Appends a CharSequence to the builder.- Parameters:
data- the CharSequence to append- Returns:
- this builder for method chaining
-
append
Appends a character array to the builder.- Parameters:
data- the character array to append- Returns:
- this builder for method chaining
-
append
Appends an Object to the builder.- Parameters:
data- the Object to append- Returns:
- this builder for method chaining
-
append
Appends a StringBuilder to the builder.- Parameters:
data- the StringBuilder to append- Returns:
- this builder for method chaining
-
append
Appends a float to the builder.- Parameters:
data- the float to append- Returns:
- this builder for method chaining
-
append
Appends a double to the builder.- Parameters:
data- the double to append- Returns:
- this builder for method chaining
-
append
Appends a long to the builder.- Parameters:
data- the long to append- Returns:
- this builder for method chaining
-
bold
Enables bold text style.- Returns:
- this builder for method chaining
-
boldOff
Disables bold text style.- Returns:
- this builder for method chaining
-
faint
Enables faint (dim) text style.- Returns:
- this builder for method chaining
-
faintOff
Disables faint text style.- Returns:
- this builder for method chaining
-
italic
Enables italic text style.- Returns:
- this builder for method chaining
-
italicOff
Disables italic text style.- Returns:
- this builder for method chaining
-
underline
Enables underline text style.- Returns:
- this builder for method chaining
-
underlineOff
Disables underline text style.- Returns:
- this builder for method chaining
-
blink
Enables blinking text style.- Returns:
- this builder for method chaining
-
blinkOff
Disables blinking text style.- Returns:
- this builder for method chaining
-
invert
Enables inverted (reverse video) text style.- Returns:
- this builder for method chaining
-
invertOff
Disables inverted text style.- Returns:
- this builder for method chaining
-
conceal
Enables concealed (hidden) text style.- Returns:
- this builder for method chaining
-
concealOff
Disables concealed text style.- Returns:
- this builder for method chaining
-
crossedOut
Enables crossed-out (strikethrough) text style.- Returns:
- this builder for method chaining
-
crossedOutOff
Disables crossed-out text style.- Returns:
- this builder for method chaining
-
newline
Appends a newline to the builder.- Returns:
- this builder for method chaining
-
bold
Appends text with bold style and disables bold after.- Parameters:
text- the text to append in bold- Returns:
- this builder for method chaining
-
faint
Appends text with faint style and resets after.- Parameters:
text- the text to append in faint style- Returns:
- this builder for method chaining
-
italic
Appends text with italic style and disables italic after.- Parameters:
text- the text to append in italic- Returns:
- this builder for method chaining
-
underline
Appends text with underline style and disables underline after.- Parameters:
text- the text to append with underline- Returns:
- this builder for method chaining
-
blink
Appends text with blink style and disables blink after.- Parameters:
text- the text to append with blink- Returns:
- this builder for method chaining
-
invert
Appends text with inverted style and disables invert after.- Parameters:
text- the text to append with invert- Returns:
- this builder for method chaining
-
conceal
Appends text with concealed style and disables conceal after.- Parameters:
text- the text to append concealed- Returns:
- this builder for method chaining
-
crossedOut
Appends text with crossed-out style and disables it after.- Parameters:
text- the text to append crossed out- Returns:
- this builder for method chaining
-
bright
Enables bright (high intensity) mode for subsequent colors.When bright mode is enabled, basic colors (red, green, etc.) will use their bright variants (codes 90-97 instead of 30-37).
Example:
ANSIBuilder.builder().bright().redText("Bright red").toString();- Returns:
- this builder for method chaining
-
brightOff
Disables bright mode, returning to normal intensity colors.- Returns:
- this builder for method chaining
-
color256
Sets the foreground color using the 256-color palette.The 256-color palette is organized as:
- 0-7: Standard colors (same as basic ANSI)
- 8-15: High intensity colors
- 16-231: 6x6x6 color cube
- 232-255: Grayscale from dark to light
- Parameters:
index- the color index (0-255)- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if index is out of range
-
bg256
Sets the background color using the 256-color palette.- Parameters:
index- the color index (0-255)- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if index is out of range
-
color256
Appends text with the specified 256-color foreground and resets.- Parameters:
index- the color index (0-255)text- the text to append- Returns:
- this builder for method chaining
-
bg256
Appends text with the specified 256-color background and resets.- Parameters:
index- the color index (0-255)text- the text to append- Returns:
- this builder for method chaining
-
rgb
Sets the foreground color using RGB values (true color).True color support requires a terminal that supports 24-bit colors. Use
TerminalColorCapability.getColorDepth()to check if the terminal supports true color.- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if any component is out of range
-
bgRgb
Sets the background color using RGB values (true color).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if any component is out of range
-
hex
Sets the foreground color using a hex color value.- Parameters:
hex- the color in hex format (e.g., "#FF5733" or "FF5733")- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if the hex string is invalid
-
bgHex
Sets the background color using a hex color value.- Parameters:
hex- the color in hex format (e.g., "#FF5733" or "FF5733")- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if the hex string is invalid
-
rgb
Appends text with the specified RGB foreground color and resets.- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)text- the text to append- Returns:
- this builder for method chaining
-
hex
Appends text with the specified hex foreground color and resets.- Parameters:
hex- the color in hex formattext- the text to append- Returns:
- this builder for method chaining
-
hsl
Sets the foreground color using HSL values (converted to RGB true color).HSL (Hue, Saturation, Lightness) is often more intuitive for color selection:
- Hue: Position on color wheel (0=red, 60=yellow, 120=green, 180=cyan, 240=blue, 300=magenta)
- Saturation: Color intensity (0=gray, 100=vivid)
- Lightness: Brightness (0=black, 50=pure color, 100=white)
Example for creating visible colors on dark terminals:
// Use high lightness (65-75) for dark backgrounds ANSIBuilder.builder().hsl(0, 80, 65).append("Red on dark").toString();- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
bgHsl
Sets the background color using HSL values (converted to RGB true color).- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)- Returns:
- this builder for method chaining
-
hsl
Appends text with the specified HSL foreground color and resets.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)text- the text to append- Returns:
- this builder for method chaining
-
bgHsl
Appends text with the specified HSL background color and resets.- Parameters:
h- hue in degrees (0-360)s- saturation as percentage (0-100)l- lightness as percentage (0-100)text- the text to append- Returns:
- this builder for method chaining
-
error
Sets the foreground color to the theme-appropriate error color (red).Color priority: RGB override > code override > capability > default.
- Returns:
- this builder for method chaining
-
error
Appends text with error styling (red) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
success
Sets the foreground color to the theme-appropriate success color (green).Color priority: RGB override > code override > capability > default.
- Returns:
- this builder for method chaining
-
success
Appends text with success styling (green) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
warning
Sets the foreground color to the theme-appropriate warning color (yellow).Color priority: RGB override > code override > capability > default.
- Returns:
- this builder for method chaining
-
warning
Appends text with warning styling (yellow) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
info
Sets the foreground color to the theme-appropriate info color (green).Color priority: RGB override > code override > capability > default.
- Returns:
- this builder for method chaining
-
info
Appends text with info styling (green) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
debug
Sets the foreground color to the theme-appropriate debug color (cyan).Color priority: RGB override > code override > capability > default.
Debug uses cyan, aligning with JBoss LogManager's color spectrum where DEBUG maps to teal/cyan:
- For dark themes: bright cyan (96)
- For light themes: dark cyan (36)
- Returns:
- this builder for method chaining
-
debug
Appends text with debug styling and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
trace
Sets the foreground color to the theme-appropriate trace color.Color priority: RGB override > code override > capability > default.
Trace is the least prominent log level, using a dim gray color that doesn't distract from more important messages:
- For dark themes: 256-color gray (242) - visible but dimmer than debug
- For light themes: gray (90) - very subdued
- Returns:
- this builder for method chaining
-
trace
Appends text with trace styling and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
timestamp
Sets the foreground color to the theme-appropriate timestamp color (gray).Color priority: RGB override > code override > capability > default.
Timestamps use a neutral gray color that is visible but doesn't distract from the main message content.
- Returns:
- this builder for method chaining
-
timestamp
Appends text with timestamp styling (gray) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
message
Sets the foreground color to the theme-appropriate message color (magenta).Color priority: RGB override > code override > capability > default.
Message color is used for highlighted or emphasized message content that should stand out from regular text.
- Returns:
- this builder for method chaining
-
message
Appends text with message styling (magenta) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
category
Sets the foreground color to the theme-appropriate category color (blue).Color priority: RGB override > code override > capability > default.
Category color is used for package/class names (logger categories) in log output. Aligns with JBoss LogManager's ColorPatternFormatter CATEGORY item (HSL 220°, 0.9, 0.8 — a blue hue).
- Returns:
- this builder for method chaining
-
category
Appends text with category styling (blue) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
threadName
Sets the foreground color to the theme-appropriate thread name color (green).Color priority: RGB override > code override > capability > default.
Thread name color is used for thread identifiers in log output. Aligns with JBoss LogManager's ColorPatternFormatter THREAD_NAME item (HSL 120°, 0.429, 0.8 — a muted green).
- Returns:
- this builder for method chaining
-
threadName
Appends text with thread name styling (green) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
fatal
Sets the foreground color to the theme-appropriate fatal color (red).Color priority: RGB override > code override > capability > default.
Fatal color is used for FATAL-level log messages — the most severe log level. Uses the same red base as error, but is typically distinguished by bold styling in usage.
- Returns:
- this builder for method chaining
-
fatal
Appends text with fatal styling (red) and resets.- Parameters:
text- the text to append- Returns:
- this builder for method chaining
-
textCode
Sets the foreground color using a raw ANSI color code.This allows direct control over the ANSI color code used:
- 30-37: Standard foreground colors
- 90-97: Bright foreground colors
- Parameters:
code- the ANSI color code- Returns:
- this builder for method chaining
-
bgCode
Sets the background color using a raw ANSI color code.This allows direct control over the ANSI color code used:
- 40-47: Standard background colors
- 100-107: Bright background colors
- Parameters:
code- the ANSI color code- Returns:
- this builder for method chaining
-
toString
Returns the built string with ANSI formatting. -
toLine
Returns the built string with ANSI formatting followed by a newline.This is a convenience method equivalent to
toString() + "\n".- Returns:
- the formatted string with a trailing newline
-
appendLine
Appends text followed by a newline.This is a convenience method equivalent to
append(text).newline().- Parameters:
text- the text to append before the newline- Returns:
- this builder for method chaining
-