Package com.yetnt.utils.builders
Class AnsiColour
java.lang.Object
com.yetnt.utils.builders.AnsiColour
A helper class which applies ANSI escape codes to strings for lovely terminal output.
Example usage:
String out = AnsiColour.print(
"Oh my Glob",
AnsiColour.FONT.BOLD,
AnsiColour.FORE.BRIGHT_PURPLE,
AnsiColour.BACK.WHITE
);
System.out.println(out);
From Jaiva!
- Author:
- Lehlogonolo Poole
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumBackground coloursstatic enumFont stylesstatic enumForeground coloursstatic interfaceAn interface representing a style that can be applied to console output. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringprint(String input, AnsiColour.Style... styles) Applies ANSI escape codes to a given string to style its output in a console.static StringprintInline(String input, AnsiColour.Style... styles) Applies ANSI escape codes to a given string to style its output in a console.static StringRemoves all ANSI colour codes froma given string
-
Constructor Details
-
AnsiColour
public AnsiColour()
-
-
Method Details
-
print
Applies ANSI escape codes to a given string to style its output in a console. The styling can include text color, background color, and font styles (e.g., bold, italic).- Parameters:
input- The string to be styled.styles- An array ofAnsiColour.Styleenums (e.g.,AnsiColour.FORE,AnsiColour.BACK,AnsiColour.FONT) to apply to the input string. If no styles are provided, the input string is returned as is.- Returns:
- The styled string with ANSI escape codes, followed by a reset code to ensure subsequent console output is not affected.
-
printInline
Applies ANSI escape codes to a given string to style its output in a console. Unlikeprint(String, Style...), this method does not append a reset code, allowing subsequent output to inherit the applied styles.- Parameters:
input- The string to be styled.styles- An array ofAnsiColour.Styleenums to apply.- Returns:
- The styled string with ANSI escape codes.
-
remove
Removes all ANSI colour codes froma given string- Parameters:
withANSI- Input with ANSI escape codes- Returns:
- input without ANSI escape codes
-