public class TermColors
The main entry point into mordant. Used to generate ANSI codes.
You typically want to use this in a with block. Colors and types can be nested, and will automatically be
reset.
This will print the text "red white and blue", with foreground colors matching the text:
with(TermColors()) {
println("${red("red")} ${white("white")} and ${blue("blue")}")
}
This will set the background color while leaving the foreground unchanged:
with(TermColors()) {
println("The foreground ${brightBlue.bg("color will stay the")} same")
}
This will set foreground and background:
with(TermColors()) {
println((yellow on brightGreen)("this is easy to read, right?"))
}
You can also mix text styles with colors:
with(TermColors()) {
println((bold + white + underline)("Listen!"))
}
| Constructor and Description |
|---|
TermColors(TermColors.Level level)
The main entry point into mordant. Used to generate ANSI codes.
|
TermColors()
The main entry point into mordant. Used to generate ANSI codes.
|
| Modifier and Type | Method and Description |
|---|---|
AnsiColorCode |
cmyk(int c,
int m,
int y,
int k)
Create a color code from a CMYK color.
|
AnsiColorCode |
color(com.github.ajalt.colormath.ConvertibleColor color)
Create a color from an existing ConvertibleColor.
|
java.lang.String |
cursorDown(int count)
Create an ANSI code to move the cursor down count cells.
|
java.lang.String |
cursorLeft(int count)
Create an ANSI code to move the cursor left count cells.
|
java.lang.String |
cursorRight(int count)
Create an ANSI code to move the cursor right count cells.
|
java.lang.String |
cursorUp(int count)
Create an ANSI code to move the cursor up count cells.
|
AnsiColorCode |
getBlack() |
AnsiColorCode |
getBlue() |
AnsiCode |
getBold()
Render text as bold or increased intensity.
|
AnsiColorCode |
getBrightBlue() |
AnsiColorCode |
getBrightCyan() |
AnsiColorCode |
getBrightGreen() |
AnsiColorCode |
getBrightMagenta() |
AnsiColorCode |
getBrightRed() |
AnsiColorCode |
getBrightWhite() |
AnsiColorCode |
getBrightYellow() |
AnsiColorCode |
getCyan() |
AnsiCode |
getDim()
Render text as faint or decreased intensity.
|
AnsiColorCode |
getGray() |
AnsiColorCode |
getGreen() |
AnsiCode |
getHidden()
Conceal text.
|
java.lang.String |
getHideCursor()
Create an ANSI code to hide the cursor.
|
AnsiCode |
getInverse()
Render text with background and foreground colors switched.
|
AnsiCode |
getItalic()
Render text as italic.
|
TermColors.Level |
getLevel() |
AnsiColorCode |
getMagenta() |
AnsiColorCode |
getRed() |
AnsiCode |
getReset()
Clear all active styles
|
java.lang.String |
getShowCursor()
Create an ANSI code to show the cursor.
|
AnsiCode |
getStrikethrough()
Render text with a strikethrough.
|
AnsiCode |
getUnderline()
Underline text.
|
AnsiColorCode |
getWhite() |
AnsiColorCode |
getYellow() |
AnsiColorCode |
gray(double fraction)
Create a grayscale color code from a fraction in the range \[0, 1].
|
AnsiColorCode |
hsl(int h,
int s,
int l)
Create a color code from an HSL color.
|
AnsiColorCode |
hsv(int h,
int s,
int v)
Create a color code from an HSV color.
|
AnsiColorCode |
lab(double l,
double a,
double b)
Create a color code from a CIE LAB color.
|
AnsiColorCode |
rgb(java.lang.String hex) |
AnsiColorCode |
rgb(int r,
int g,
int b)
Create a color code from an RGB color.
|
AnsiColorCode |
xyz(double x,
double y,
double z)
Create a color code from a CIE XYZ color.
|
public TermColors(TermColors.Level level)
The main entry point into mordant. Used to generate ANSI codes.
You typically want to use this in a with block. Colors and types can be nested, and will automatically be
reset.
This will print the text "red white and blue", with foreground colors matching the text:
with(TermColors()) {
println("${red("red")} ${white("white")} and ${blue("blue")}")
}
This will set the background color while leaving the foreground unchanged:
with(TermColors()) {
println("The foreground ${brightBlue.bg("color will stay the")} same")
}
This will set foreground and background:
with(TermColors()) {
println((yellow on brightGreen)("this is easy to read, right?"))
}
You can also mix text styles with colors:
with(TermColors()) {
println((bold + white + underline)("Listen!"))
}
public TermColors()
The main entry point into mordant. Used to generate ANSI codes.
You typically want to use this in a with block. Colors and types can be nested, and will automatically be
reset.
This will print the text "red white and blue", with foreground colors matching the text:
with(TermColors()) {
println("${red("red")} ${white("white")} and ${blue("blue")}")
}
This will set the background color while leaving the foreground unchanged:
with(TermColors()) {
println("The foreground ${brightBlue.bg("color will stay the")} same")
}
This will set foreground and background:
with(TermColors()) {
println((yellow on brightGreen)("this is easy to read, right?"))
}
You can also mix text styles with colors:
with(TermColors()) {
println((bold + white + underline)("Listen!"))
}
public AnsiColorCode getBlack()
public AnsiColorCode getRed()
public AnsiColorCode getGreen()
public AnsiColorCode getYellow()
public AnsiColorCode getBlue()
public AnsiColorCode getMagenta()
public AnsiColorCode getCyan()
public AnsiColorCode getWhite()
public AnsiColorCode getGray()
public AnsiColorCode getBrightRed()
public AnsiColorCode getBrightGreen()
public AnsiColorCode getBrightYellow()
public AnsiColorCode getBrightBlue()
public AnsiColorCode getBrightMagenta()
public AnsiColorCode getBrightCyan()
public AnsiColorCode getBrightWhite()
public AnsiCode getReset()
Clear all active styles
public AnsiCode getBold()
Render text as bold or increased intensity.
Might be rendered as a different color instead of a different font weight.
public AnsiCode getDim()
Render text as faint or decreased intensity.
Not widely supported.
public AnsiCode getItalic()
Render text as italic.
Not widely supported, might be rendered as inverse instead of italic.
public AnsiCode getUnderline()
Underline text.
Might be rendered with different colors instead of underline.
public AnsiCode getInverse()
Render text with background and foreground colors switched.
public AnsiCode getHidden()
Conceal text.
Not widely supported.
public AnsiCode getStrikethrough()
Render text with a strikethrough.
Not widely supported.
public AnsiColorCode rgb(java.lang.String hex)
hex - An rgb hex string in the form "#ffffff" or "ffffff"public AnsiColorCode rgb(int r, int g, int b)
Create a color code from an RGB color.
r - The red amount, in the range \[0, 255]g - The green amount, in the range \[0, 255]b - The blue amount, in the range \[0, 255]public AnsiColorCode hsl(int h, int s, int l)
Create a color code from an HSL color.
h - The hue, in the range \[0, 360]s - The saturation, in the range \[0, 100]l - The lightness, in the range \[0, 100]public AnsiColorCode hsv(int h, int s, int v)
Create a color code from an HSV color.
h - The hue, in the range \[0, 360]s - The saturation, in the range \[0,100]v - The value, in the range \[0,100]public AnsiColorCode cmyk(int c, int m, int y, int k)
Create a color code from a CMYK color.
c - The cyan amount, in the range \[0, 100]m - The magenta amount, in the range \[0,100]y - The yellow amount, in the range \[0,100]k - The black amount, in the range \[0,100]public AnsiColorCode gray(double fraction)
Create a grayscale color code from a fraction in the range \[0, 1].
fraction - The fraction of white in the color. 0 is pure black, 1 is pure white.public AnsiColorCode xyz(double x, double y, double z)
Create a color code from a CIE XYZ color.
Conversions use D65 reference white, and sRGB profile.
x, y, and z are generally in the interval 0,100, but may be larger
public AnsiColorCode lab(double l, double a, double b)
public java.lang.String cursorUp(int count)
Create an ANSI code to move the cursor up count cells.
If ANSI codes are not supported, or count is 0, an empty string is returned. If count is negative, the cursor will be moved down instead.
public java.lang.String cursorDown(int count)
Create an ANSI code to move the cursor down count cells.
If ANSI codes are not supported, or count is 0, an empty string is returned. If count is negative, the cursor will be moved up instead.
public java.lang.String cursorLeft(int count)
Create an ANSI code to move the cursor left count cells.
If ANSI codes are not supported, or count is 0, an empty string is returned. If count is negative, the cursor will be moved right instead.
public java.lang.String cursorRight(int count)
Create an ANSI code to move the cursor right count cells.
If ANSI codes are not supported, or count is 0, an empty string is returned. If count is negative, the cursor will be moved left instead.
public java.lang.String getHideCursor()
Create an ANSI code to hide the cursor.
If ANSI codes are not supported, an empty string is returned.
public java.lang.String getShowCursor()
Create an ANSI code to show the cursor.
If ANSI codes are not supported, an empty string is returned.
public AnsiColorCode color(com.github.ajalt.colormath.ConvertibleColor color)
Create a color from an existing ConvertibleColor.
It's usually easier to use a function like TermColors.rgb or TermColors.hsl instead.
TermColors.rgb,
TermColors.hslpublic TermColors.Level getLevel()