Class AnsiColour

java.lang.Object
com.yetnt.utils.builders.AnsiColour

public final class AnsiColour extends Object
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
  • Constructor Details

    • AnsiColour

      public AnsiColour()
  • Method Details

    • print

      public static String print(String input, AnsiColour.Style... styles)
      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 of AnsiColour.Style enums (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

      public static String printInline(String input, AnsiColour.Style... styles)
      Applies ANSI escape codes to a given string to style its output in a console. Unlike print(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 of AnsiColour.Style enums to apply.
      Returns:
      The styled string with ANSI escape codes.
    • remove

      public static String remove(String withANSI)
      Removes all ANSI colour codes froma given string
      Parameters:
      withANSI - Input with ANSI escape codes
      Returns:
      input without ANSI escape codes