Class GTerminal

java.lang.Object
com.glitchybyte.glib.terminal.GTerminal

public final class GTerminal extends Object
Helper class to print color text to console. It assumes 256 colors (at least). If there is no console, it will do nothing.

Example usage:

 GTerminal.print("This is " + GTerminal.text("cyan", GTerminal.COLOR_CYAN, null) + " text.\n");
 GTerminal.println("And this is %s text.", GTerminal.text("orange", GTerminal.rgb(5, 2, 1), null));
 GTerminal.flush();
See Also:
  • Field Details

    • IN_TERMINAL

      public static boolean IN_TERMINAL
      Flag to check if we are running in a terminal.
    • CC_CR

      public static final String CC_CR
      Carriage return.
      See Also:
    • COLOR_BLACK

      public static final Integer COLOR_BLACK
      Black.
    • COLOR_RED

      public static final Integer COLOR_RED
      Red.
    • COLOR_GREEN

      public static final Integer COLOR_GREEN
      Green.
    • COLOR_YELLOW

      public static final Integer COLOR_YELLOW
      Yellow.
    • COLOR_BLUE

      public static final Integer COLOR_BLUE
      Blue.
    • COLOR_MAGENTA

      public static final Integer COLOR_MAGENTA
      Magenta.
    • COLOR_CYAN

      public static final Integer COLOR_CYAN
      Cyan.
    • COLOR_WHITE

      public static final Integer COLOR_WHITE
      White (light gray).
    • COLOR_BRIGHT_BLACK

      public static final Integer COLOR_BRIGHT_BLACK
      Bright black (dark gray).
    • COLOR_BRIGHT_RED

      public static final Integer COLOR_BRIGHT_RED
      Bright red.
    • COLOR_BRIGHT_GREEN

      public static final Integer COLOR_BRIGHT_GREEN
      Bright green.
    • COLOR_BRIGHT_YELLOW

      public static final Integer COLOR_BRIGHT_YELLOW
      Bright yellow.
    • COLOR_BRIGHT_BLUE

      public static final Integer COLOR_BRIGHT_BLUE
      Bright blue.
    • COLOR_BRIGHT_MAGENTA

      public static final Integer COLOR_BRIGHT_MAGENTA
      Bright magenta.
    • COLOR_BRIGHT_CYAN

      public static final Integer COLOR_BRIGHT_CYAN
      Bright cyan.
    • COLOR_BRIGHT_WHITE

      public static final Integer COLOR_BRIGHT_WHITE
      Bright white (white).
  • Method Details

    • print

      public static void print(String format, Object... args)
      Prints to terminal.
      Parameters:
      format - Format of message to print.
      args - Arguments of format.
    • println

      public static void println(String format, Object... args)
      Prints to terminal, and adds a new line.
      Parameters:
      format - Format of message to print.
      args - Arguments of format.
    • clearCurrentLine

      public static String clearCurrentLine()
      Returns a String that will clear the current line when printed.
      Returns:
      String with encoded command.
    • clearToEndOfLine

      public static String clearToEndOfLine()
      Returns a String that will clear to end of line when printed.
      Returns:
      String with encoded command.
    • clearToStartOfLine

      public static String clearToStartOfLine()
      Returns a String that will clear to start of line when printed.
      Returns:
      String with encoded command.
    • cursorUp

      public static String cursorUp(int n)
      Returns a String that will move the cursor up n number of times when printed.
      Parameters:
      n - Number of times to move the cursor.
      Returns:
      String with encoded command.
    • cursorDown

      public static String cursorDown(int n)
      Returns a String that will move the cursor down n number of times when printed.
      Parameters:
      n - Number of times to move the cursor.
      Returns:
      String with encoded command.
    • cursorLeft

      public static String cursorLeft(int n)
      Returns a String that will move the cursor left n number of times when printed.
      Parameters:
      n - Number of times to move the cursor.
      Returns:
      String with encoded command.
    • cursorRight

      public static String cursorRight(int n)
      Returns a String that will move the cursor right n number of times when printed.
      Parameters:
      n - Number of times to move the cursor.
      Returns:
      String with encoded command.
    • resetColor

      public static String resetColor()
      Returns a String that will reset colors when printed.
      Returns:
      String with encoded command.
    • rgb

      public static Integer rgb(int r, int g, int b)
      Creates the corresponding color code for the given RGB value.
      Parameters:
      r - Red component [0, 6)
      g - Green component [0, 6)
      b - Blue component [0, 6)
      Returns:
      Color code.
    • grey

      public static Integer grey(int step)
      Creates the corresponding color code for the given grey step value, from dark to bright.
      Parameters:
      step - Grey step [0, 24)
      Returns:
      Color code.
    • foregroundColor

      public static String foregroundColor(int color)
      Returns a String that will change the foreground color.
      Parameters:
      color - Color code.
      Returns:
      String with encoded command.
    • backgroundColor

      public static String backgroundColor(int color)
      Returns a String that will change the background color.
      Parameters:
      color - Color code.
      Returns:
      String with encoded command.
    • text

      public static String text(String text, Integer fgColor, Integer bgColor)
      Returns a String that represents text with the given colors when printed.
      Parameters:
      text - Test to print.
      fgColor - Foreground color code.
      bgColor - Background color code.
      Returns:
      String with encoded command.
    • text

      public static String text(String text, Integer fgColor)
      Returns a String that represents text with the given foreground color when printed.
      Parameters:
      text - Test to print.
      fgColor - Foreground color code.
      Returns:
      String with encoded command.
    • flush

      public static void flush()
      Flushes all printed commands.

      It is possible console will not update until it's flushed. Flush when you want to make sure the user sees your print output.