Package com.glitchybyte.glib.terminal
Class GTerminal
java.lang.Object
com.glitchybyte.glib.terminal.GTerminal
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCarriage return.static final IntegerBlack.static final IntegerBlue.static final IntegerBright black (dark gray).static final IntegerBright blue.static final IntegerBright cyan.static final IntegerBright green.static final IntegerBright magenta.static final IntegerBright red.static final IntegerBright white (white).static final IntegerBright yellow.static final IntegerCyan.static final IntegerGreen.static final IntegerMagenta.static final IntegerRed.static final IntegerWhite (light gray).static final IntegerYellow.static booleanFlag to check if we are running in a terminal. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbackgroundColor(int color) Returns aStringthat will change the background color.static StringReturns aStringthat will clear the current line when printed.static StringReturns aStringthat will clear to end of line when printed.static StringReturns aStringthat will clear to start of line when printed.static StringcursorDown(int n) Returns aStringthat will move the cursor downnnumber of times when printed.static StringcursorLeft(int n) Returns aStringthat will move the cursor leftnnumber of times when printed.static StringcursorRight(int n) Returns aStringthat will move the cursor rightnnumber of times when printed.static StringcursorUp(int n) Returns aStringthat will move the cursor upnnumber of times when printed.static voidflush()Flushes all printed commands.static StringforegroundColor(int color) Returns aStringthat will change the foreground color.static Integergrey(int step) Creates the corresponding color code for the given greystepvalue, from dark to bright.static voidPrints to terminal.static voidPrints to terminal, and adds a new line.static StringReturns aStringthat will reset colors when printed.static Integerrgb(int r, int g, int b) Creates the corresponding color code for the given RGB value.static StringReturns aStringthat representstextwith the given foreground color when printed.static StringReturns aStringthat representstextwith the given colors when printed.
-
Field Details
-
IN_TERMINAL
public static boolean IN_TERMINALFlag to check if we are running in a terminal. -
CC_CR
Carriage return.- See Also:
-
COLOR_BLACK
Black. -
COLOR_RED
Red. -
COLOR_GREEN
Green. -
COLOR_YELLOW
Yellow. -
COLOR_BLUE
Blue. -
COLOR_MAGENTA
Magenta. -
COLOR_CYAN
Cyan. -
COLOR_WHITE
White (light gray). -
COLOR_BRIGHT_BLACK
Bright black (dark gray). -
COLOR_BRIGHT_RED
Bright red. -
COLOR_BRIGHT_GREEN
Bright green. -
COLOR_BRIGHT_YELLOW
Bright yellow. -
COLOR_BRIGHT_BLUE
Bright blue. -
COLOR_BRIGHT_MAGENTA
Bright magenta. -
COLOR_BRIGHT_CYAN
Bright cyan. -
COLOR_BRIGHT_WHITE
Bright white (white).
-
-
Method Details
-
print
Prints to terminal.- Parameters:
format- Format of message to print.args- Arguments of format.
-
println
Prints to terminal, and adds a new line.- Parameters:
format- Format of message to print.args- Arguments of format.
-
clearCurrentLine
Returns aStringthat will clear the current line when printed.- Returns:
Stringwith encoded command.
-
clearToEndOfLine
Returns aStringthat will clear to end of line when printed.- Returns:
Stringwith encoded command.
-
clearToStartOfLine
Returns aStringthat will clear to start of line when printed.- Returns:
Stringwith encoded command.
-
cursorUp
Returns aStringthat will move the cursor upnnumber of times when printed.- Parameters:
n- Number of times to move the cursor.- Returns:
Stringwith encoded command.
-
cursorDown
Returns aStringthat will move the cursor downnnumber of times when printed.- Parameters:
n- Number of times to move the cursor.- Returns:
Stringwith encoded command.
-
cursorLeft
Returns aStringthat will move the cursor leftnnumber of times when printed.- Parameters:
n- Number of times to move the cursor.- Returns:
Stringwith encoded command.
-
cursorRight
Returns aStringthat will move the cursor rightnnumber of times when printed.- Parameters:
n- Number of times to move the cursor.- Returns:
Stringwith encoded command.
-
resetColor
Returns aStringthat will reset colors when printed.- Returns:
Stringwith encoded command.
-
rgb
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
Creates the corresponding color code for the given greystepvalue, from dark to bright.- Parameters:
step- Grey step [0, 24)- Returns:
- Color code.
-
foregroundColor
Returns aStringthat will change the foreground color.- Parameters:
color- Color code.- Returns:
Stringwith encoded command.
-
backgroundColor
Returns aStringthat will change the background color.- Parameters:
color- Color code.- Returns:
Stringwith encoded command.
-
text
Returns aStringthat representstextwith the given colors when printed.- Parameters:
text- Test to print.fgColor- Foreground color code.bgColor- Background color code.- Returns:
Stringwith encoded command.
-
text
Returns aStringthat representstextwith the given foreground color when printed.- Parameters:
text- Test to print.fgColor- Foreground color code.- Returns:
Stringwith 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.
-