Class Ansi

java.lang.Object
com.marcpg.libpg.color.Ansi

public class Ansi extends Object
Ansi formatting can be used in nearly any text-based console. It is very commonly used and supports many different formatting options, from bold, to blinking, to colored text, just everything.
Since:
0.0.1
  • Field Details

    • RESET

      public static final Ansi RESET
      Resets all formatting
    • RESET_FG

      public static final Ansi RESET_FG
      Resets the foreground color
    • RESET_BG

      public static final Ansi RESET_BG
      Resets the background color
    • BOLD

      public static final Ansi BOLD
      Makes the text bold/thick
    • ITALIC

      public static final Ansi ITALIC
      Makes the text italic/cursive
    • UNDERLINE

      public static final Ansi UNDERLINE
      Underlines the text
    • SWAP_BG_FG

      public static final Ansi SWAP_BG_FG
      Swaps the foreground and background colors
    • STRIKETHROUGH

      public static final Ansi STRIKETHROUGH
      Makes the text strikethrough
    • DEFAULT_FONT

      public static final Ansi DEFAULT_FONT
      Resets the font
    • ALT_FONT

      public static final Ansi ALT_FONT
      Use the alternate font
    • UNDERLINE_OFF

      public static final Ansi UNDERLINE_OFF
      Turns underlined off
    • ITALIC_OFF

      public static final Ansi ITALIC_OFF
      Turns italic/cursive off
    • STRIKETHROUGH_OFF

      public static final Ansi STRIKETHROUGH_OFF
      Turns strikethrough off
    • FRAMED

      public static final Ansi FRAMED
      Good Question
    • ENCIRCLED

      public static final Ansi ENCIRCLED
      Good Question
    • OVERLINED

      public static final Ansi OVERLINED
      Overlines the text, not widely supported
    • BLACK

      public static final Ansi BLACK
      Black
    • DARK_RED

      public static final Ansi DARK_RED
      Dark Red
    • GREEN

      public static final Ansi GREEN
      Dark Green
    • BROWN

      public static final Ansi BROWN
      Brown / Orange / Ugly Yellow
    • BLUE

      public static final Ansi BLUE
      Blue
    • MAGENTA

      public static final Ansi MAGENTA
      Dark Magenta
    • CYAN

      public static final Ansi CYAN
      Cyan / Aqua
    • GRAY

      public static final Ansi GRAY
      Gray
    • DARK_GRAY

      public static final Ansi DARK_GRAY
      Dark Gray
    • RED

      public static final Ansi RED
      Red
    • LIME

      public static final Ansi LIME
      Lime / Bright Green
    • YELLOW

      public static final Ansi YELLOW
      Yellow
    • BRIGHT_BLUE

      public static final Ansi BRIGHT_BLUE
      Bright Blue
    • PINK

      public static final Ansi PINK
      Pink / Bright Magenta
    • BRIGHT_CYAN

      public static final Ansi BRIGHT_CYAN
      Bright Cyan/Aqua
    • WHITE

      public static final Ansi WHITE
      White, same as RESET_FG / RESET_BG
  • Method Details

    • getBackground

      public String getBackground()
      Gets the color as a background color. This only works if it's really a color, otherwise it just returns the same as get()
      Returns:
      The color as a background color
      Since:
      0.0.1
    • get

      public String get()
      Gets the format as a string, so it's usable.
      Returns:
      The ansi escape sequence
      Since:
      0.0.1
    • toString

      public String toString()
      Same as get()
      Overrides:
      toString in class Object
      Returns:
      The ansi escape sequence
      Since:
      0.0.1
    • fromRGB

      @NotNull public static @NotNull Ansi fromRGB(int r, int g, int b)
      Get a custom Ansi color based on red, green and blue color values.
      Parameters:
      r - Red (0-255)
      g - Green (0-255)
      b - Blue (0-255)
      Returns:
      A custom ansi color
      Since:
      0.0.1
    • fromColor

      @NotNull public static @NotNull Ansi fromColor(@NotNull @NotNull Color color)
      Get a custom Ansi color based on a Java AWT color.
      Parameters:
      color - The Java AWT color
      Returns:
      A custom ansi color
      Since:
      0.0.1
    • formattedString

      @NotNull public static @NotNull String formattedString(String text, Ansi @NotNull ... formats)
      Apply a custom ansi format to a string
      Parameters:
      text - The string that should be formatted
      formats - What format should be applied
      Returns:
      The formatted string
      Since:
      0.0.1
    • gray

      @NotNull public static @NotNull String gray(String text)
      Colors a specified text gray, which can be used for secondary text for example.
      Uses dark gray, as some consoles make normal gray appear white.
      Parameters:
      text - The text to color gray.
      Returns:
      The colored text.
      See Also:
    • red

      @NotNull public static @NotNull String red(String text)
      Colors a specified text red, which can be used for errors for example.
      Parameters:
      text - The text to color red.
      Returns:
      The colored text.
      See Also:
    • yellow

      @NotNull public static @NotNull String yellow(String text)
      Colors a specified text yellow, which can be used for warnings for example.
      Parameters:
      text - The text to color yellow.
      Returns:
      The colored text.
      See Also:
    • green

      @NotNull public static @NotNull String green(String text)
      Colors a specified text green, which can be used for infos or successes for example.
      Parameters:
      text - The text to color green.
      Returns:
      The colored text.
      See Also:
    • blink

      @NotNull public static @NotNull String blink(String text)
      Makes the specified text blink.
      Parameters:
      text - The text to make blink.
      Returns:
      The blinking text.
      See Also:
    • bold

      @NotNull public static @NotNull String bold(String text)
      Makes the specified text bold/thick.
      Parameters:
      text - The text to make bold/thick.
      Returns:
      The bold/thick text.
      See Also:
    • italic

      @NotNull public static @NotNull String italic(String text)
      Makes the specified text italic.
      Parameters:
      text - The text to make italic.
      Returns:
      The italic text.
      See Also: