- All Implemented Interfaces:
Serializable
,Comparable<AnsiEscapeCode>
,Constable
,org.refcodes.mixin.CodeAccessor<Byte>
public enum AnsiEscapeCode
extends Enum<AnsiEscapeCode>
implements org.refcodes.mixin.CodeAccessor<Byte>
This enumeration contains ANSI Escape-Codes for modifying the appearance of
console output to ANSI enabled terminals. In order to compose your basic ANSI
Escape-Code sequences, you may go for
toEscapeSequence(AnsiEscapeCode...)
. Use
toEscapedSequence(String)
when you wish to print the ANSI
Escape-Code sequence without the sequence modifying your terminal output
(e.g. helpful in error messages regarding ANSI Escape-Codes).-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
Nested classes/interfaces inherited from interface org.refcodes.mixin.CodeAccessor
org.refcodes.mixin.CodeAccessor.CodeBuilder<T extends Object,
B extends org.refcodes.mixin.CodeAccessor.CodeBuilder<T, B>>, org.refcodes.mixin.CodeAccessor.CodeMutator<T extends Object>, org.refcodes.mixin.CodeAccessor.CodeProperty<T extends Object> -
Enum Constant Summary
Enum ConstantDescriptionBackground Black: Set background color.Background Blue: Set background color.Background Bright Black: Set bright background color (aixterm (not in standard)).Background Bright Blue: Set bright background color (aixterm (not in standard)).Background Bright Cyan: Set bright background color (aixterm (not in standard)).Background Bright Default: Set bright background color (aixterm (not in standard)).Background Bright Green: Set bright background color (aixterm (not in standard)).Background Bright Magenta: Set bright background color (aixterm (not in standard)).Background Bright Red: Set bright background color (aixterm (not in standard)).Background Bright White: Set bright background color (aixterm (not in standard)).Background Bright Yellow: Set bright background color (aixterm (not in standard)).Background Cyan: Set background color.Background Green: Set background color.Background Magenta: Set background color.Background Red: Set background color.Background White: Set background color.Background Yellow: Set background color.Blink offBold or increased intensity:Conceal: Not widely supported.Crossed-out: Characters legible but marked for deletion.Default background color: implementation defined (according to standard)Primary(default) fontDefault foreground color: implementation defined (according to standard)Doubly underline or Bold off: Double-underline per ECMA-48.EncircledFaint (decreased intensity):Foreground Black: Set foreground color.Foreground Blue: Set foreground color.Foreground Bright Black: Set bright foreground color (aixterm (not in standard)).Foreground Bright Blue: Set bright foreground color (aixterm (not in standard)).Foreground Bright Cyan: Set bright foreground color (aixterm (not in standard)).Foreground Bright Default: Set bright foreground color (aixterm (not in standard)).Foreground Bright Green: Set bright foreground color (aixterm (not in standard)).Foreground Bright Magenta: Set bright foreground color (aixterm (not in standard)).Foreground Bright Red: Set bright foreground color (aixterm (not in standard)).Foreground Bright White: Set bright foreground color (aixterm (not in standard)).Foreground Bright Yellow: Set bright foreground color (aixterm (not in standard)).Foreground Cyan: Set foreground color.Foreground Green: Set foreground color.Foreground Magenta: Set foreground color.Foreground Red: Set foreground color.Foreground White: Set foreground color.Foreground Yellow: Set foreground color.Font 1: Select alternative font 1.Font 2: Select alternative font 2.Font 3: Select alternative font 3.Font 4: Select alternative font 4.Font 5: Select alternative font 5.Font 6: Select alternative font 6.Font 7: Select alternative font 7.Font 8: Select alternative font 8.Font 9: Select alternative font 9.Fraktur: Rarely supported.FramedIdeogram attributes off: Reset the effects of all of 60–64.Ideogram double overline or double line on the left side : Rarely supported.Ideogram double underline or double line on the right side : Rarely supported.Ideogram overline or left side line : Rarely supported.Ideogram stress marking : Rarely supported.Ideogram underline or right side line: Rarely supported.Inverse offItalic: Not widely supported.Normal color or intensity: Neither bold nor faint.Not crossed outNot framed or encircledNot italic: Not Fraktur.Not overlinedOverlinedRapid Blink: 150+ per minute.Reset / Normal: All attributes off (reset).Reveal: Conceal off.Reverse Video: Swap foreground and background colors.Set background color: Next arguments are5;n
or2;r;g;b
, see below:ESC[48:5:(n)m
; Select background color, (n) represents an index into a predefined 256-color lookup tableESC[48;2;(r);(g);(b)m
: Select RGB background color, (r) represents the 8 bit red portion of an RGB color, (g) represents the 8 bit green portion of an RGB color, (b) represents the 8 bit blue portion of an RGB colorSet foreground color: Next arguments are5;n
or2;r;g;b
, see below:ESC[38:5:(n)m
: Select foreground color, (n) represents an index into a predefined 256-color lookup tableESC[38;2;(r);(g);(b)m
: Select RGB foreground color, (r) represents the 8 bit red portion of an RGB color, (g) represents the 8 bit green portion of an RGB color, (b) represents the 8 bit blue portion of an RGB colorSlow Blink: Less than 150 per minute.UnderlineUnderline off: Not singly or doubly underlined. -
Field Summary
Modifier and TypeFieldDescriptionstatic char
In case ofSET_FOREGROUND_COLOR
orSET_BACKGROUND_COLOR
, theCOLOR_TABLE_SELECTOR_PARAMETER
specifies that the succeeding parameter represents an index into the ANSI Color-Table.static char
The ANSI Escape-Code with which each ANSI escape sequence is commenced.static char
The delimiter used to separate the parameters of an ANSI Escape-Sequence, e.g. the parameters "0", "1" and ""4" of the sequence "<ESC>[0;1;4m
".static char
The delimiter used to separate the leading Escape-Code <ESC> of an ANSI Escape-Sequence from the succeeding portion, e.g. "[" separates <ESC> from "[0;1;4m" of the sequence "<ESC>[0;1;4m
".static char
The ANSI Escape-Code with which each ANSI escape sequence is concluded.static char
In case ofSET_FOREGROUND_COLOR
orSET_BACKGROUND_COLOR
, theRGB_COLOR_SELECTOR_PARAMETER
specifies that the succeeding parameters represent RGB values. -
Method Summary
Modifier and TypeMethodDescriptiongetCode()
Returns the escaped ANSI Escape-Code to be printable without triggering the actual ANSI escape commands.static String
toEscapedSequence
(String aEscapeSequence) Makes the provided Escape-Sequence printable by replacing theESCAPE
code with a printable char sequence.static Region[]
toEscapedSequenceRegions
(String aEscapedString) Retrieves a list of regions (begin index, end index ) with ANSI escape codes.Returns the plain ANSI escape sequence for thisAnsiEscapeCode
element.static String
toEscapeSequence
(AnsiEscapeCode... aAnsiEscapeCodes) Basic functionality to create an ANSI Escape-Code sequence from the providedAnsiEscapeCode
elements directly printable toSystem.out
.static int
Returns the length of the text, considering whether the text is expected to have ANSI escape codes not considered to be part of the length.static int
toUnescapedLength
(String aEscapedString) static String
toUnescapedString
(String aEscapedString) Removes any ANSI escape codes from the providedString
.static AnsiEscapeCode
Returns the enum constant of this class with the specified name.static AnsiEscapeCode[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
RESET
Reset / Normal: All attributes off (reset). -
BOLD
Bold or increased intensity: -
FAINT
Faint (decreased intensity): -
ITALIC
Italic: Not widely supported. Sometimes treated as inverse. -
UNDERLINE
Underline -
SLOW_BLINK
Slow Blink: Less than 150 per minute. -
RAPID_BLINK
Rapid Blink: 150+ per minute. Not widely supported. -
REVERSE_VIDEO
Reverse Video: Swap foreground and background colors. -
CONCEAL
Conceal: Not widely supported. -
CROSSED_OUT
Crossed-out: Characters legible but marked for deletion. -
DEFAULT_FONT
Primary(default) font -
FONT_1
Font 1: Select alternative font 1. -
FONT_2
Font 2: Select alternative font 2. -
FONT_3
Font 3: Select alternative font 3. -
FONT_4
Font 4: Select alternative font 4. -
FONT_5
Font 5: Select alternative font 5. -
FONT_6
Font 6: Select alternative font 6. -
FONT_7
Font 7: Select alternative font 7. -
FONT_8
Font 8: Select alternative font 8. -
FONT_9
Font 9: Select alternative font 9. -
FRAKTUR
Fraktur: Rarely supported. -
DOUBLY_UNDERLINE_OR_BOLD_OFF
Doubly underline or Bold off: Double-underline per ECMA-48. -
NORMAL_COLOR_OR_INTENSITY
Normal color or intensity: Neither bold nor faint. -
NOT_ITALIC_NOT_FRAKTUR
Not italic: Not Fraktur. -
UNDERLINE_OFF
Underline off: Not singly or doubly underlined. -
BLINK_OFF
Blink off -
INVERSE_OFF
Inverse off -
REVEAL
Reveal: Conceal off. -
NOT_CROSSED_OUT
Not crossed out -
FG_BLACK
Foreground Black: Set foreground color. -
FG_RED
Foreground Red: Set foreground color. -
FG_GREEN
Foreground Green: Set foreground color. -
FG_YELLOW
Foreground Yellow: Set foreground color. -
FG_BLUE
Foreground Blue: Set foreground color. -
FG_MAGENTA
Foreground Magenta: Set foreground color. -
FG_CYAN
Foreground Cyan: Set foreground color. -
FG_WHITE
Foreground White: Set foreground color. -
SET_FOREGROUND_COLOR
Set foreground color: Next arguments are5;n
or2;r;g;b
, see below:ESC[38:5:(n)m
: Select foreground color, (n) represents an index into a predefined 256-color lookup tableESC[38;2;(r);(g);(b)m
: Select RGB foreground color, (r) represents the 8 bit red portion of an RGB color, (g) represents the 8 bit green portion of an RGB color, (b) represents the 8 bit blue portion of an RGB color
-
DEFAULT_FOREGROUND_COLOR
Default foreground color: implementation defined (according to standard) -
BG_BLACK
Background Black: Set background color. -
BG_RED
Background Red: Set background color. -
BG_GREEN
Background Green: Set background color. -
BG_YELLOW
Background Yellow: Set background color. -
BG_BLUE
Background Blue: Set background color. -
BG_MAGENTA
Background Magenta: Set background color. -
BG_CYAN
Background Cyan: Set background color. -
BG_WHITE
Background White: Set background color. -
SET_BACKGROUND_COLOR
Set background color: Next arguments are5;n
or2;r;g;b
, see below:ESC[48:5:(n)m
; Select background color, (n) represents an index into a predefined 256-color lookup tableESC[48;2;(r);(g);(b)m
: Select RGB background color, (r) represents the 8 bit red portion of an RGB color, (g) represents the 8 bit green portion of an RGB color, (b) represents the 8 bit blue portion of an RGB color
-
DEFAULT_BACKGROUND_COLOR
Default background color: implementation defined (according to standard) -
FRAMED
Framed -
ENCIRCLED
Encircled -
OVERLINED
Overlined -
NOT_FRAMED
Not framed or encircled -
NOT_OVERLINED
Not overlined -
IDEOGRAM_UNDERLINE_OR_RIGHT_SIDE_LINE
Ideogram underline or right side line: Rarely supported. -
IDEOGRAM_DOUBLE_UNDERLINE_OR_DOUBLE_LINE_ON_THE_RIGHT_SIDE
Ideogram double underline or double line on the right side : Rarely supported. -
IDEOGRAM_OVERLINE_OR_LEFT_SIDE_LINE
Ideogram overline or left side line : Rarely supported. -
IDEOGRAM_DOUBLE_OVERLINE_OR_DOUBLE_LINE_ON_THE_LEFT_SIDE
Ideogram double overline or double line on the left side : Rarely supported. -
IDEOGRAM_STRESS_MARKING
Ideogram stress marking : Rarely supported. -
IDEOGRAM_ATTRIBUTES_OFF
Ideogram attributes off: Reset the effects of all of 60–64. -
FG_BRIGHT_BLACK
Foreground Bright Black: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_RED
Foreground Bright Red: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_GREEN
Foreground Bright Green: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_YELLOW
Foreground Bright Yellow: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_BLUE
Foreground Bright Blue: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_MAGENTA
Foreground Bright Magenta: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_CYAN
Foreground Bright Cyan: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_WHITE
Foreground Bright White: Set bright foreground color (aixterm (not in standard)). -
FG_BRIGHT_DEFAULT
Foreground Bright Default: Set bright foreground color (aixterm (not in standard)). -
BG_BRIGHT_BLACK
Background Bright Black: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_RED
Background Bright Red: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_GREEN
Background Bright Green: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_YELLOW
Background Bright Yellow: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_BLUE
Background Bright Blue: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_MAGENTA
Background Bright Magenta: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_CYAN
Background Bright Cyan: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_WHITE
Background Bright White: Set bright background color (aixterm (not in standard)). -
BG_BRIGHT_DEFAULT
Background Bright Default: Set bright background color (aixterm (not in standard)).
-
-
Field Details
-
ESCAPE
public static char ESCAPEThe ANSI Escape-Code with which each ANSI escape sequence is commenced. -
ESCAPE_SUFFIX
public static char ESCAPE_SUFFIXThe ANSI Escape-Code with which each ANSI escape sequence is concluded. -
ESCAPE_PARAMETER_DELIMITER
public static char ESCAPE_PARAMETER_DELIMITERThe delimiter used to separate the parameters of an ANSI Escape-Sequence, e.g. the parameters "0", "1" and ""4" of the sequence "<ESC>[0;1;4m
". -
ESCAPE_PREFIX_DELIMITER
public static char ESCAPE_PREFIX_DELIMITERThe delimiter used to separate the leading Escape-Code <ESC> of an ANSI Escape-Sequence from the succeeding portion, e.g. "[" separates <ESC> from "[0;1;4m" of the sequence "<ESC>[0;1;4m
". -
RGB_COLOR_SELECTOR_PARAMETER
public static char RGB_COLOR_SELECTOR_PARAMETERIn case ofSET_FOREGROUND_COLOR
orSET_BACKGROUND_COLOR
, theRGB_COLOR_SELECTOR_PARAMETER
specifies that the succeeding parameters represent RGB values. -
COLOR_TABLE_SELECTOR_PARAMETER
public static char COLOR_TABLE_SELECTOR_PARAMETERIn case ofSET_FOREGROUND_COLOR
orSET_BACKGROUND_COLOR
, theCOLOR_TABLE_SELECTOR_PARAMETER
specifies that the succeeding parameter represents an index into the ANSI Color-Table.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getCode
- Specified by:
getCode
in interfaceorg.refcodes.mixin.CodeAccessor<Byte>
-
toEscapeSequence
Returns the plain ANSI escape sequence for thisAnsiEscapeCode
element. UsetoEscapeSequence(AnsiEscapeCode...)
if you require an ANSI escape sequence consisting of more than just oneAnsiEscapeCode
.- Returns:
- The correctly generated Escape-Code sequence directly printable
to
System.out
.
-
toEscapeSequence
Basic functionality to create an ANSI Escape-Code sequence from the providedAnsiEscapeCode
elements directly printable toSystem.out
. This method can only provide placeholder such as ${n0}, ${n1}, ... for elementsSET_FOREGROUND_COLOR
andSET_BACKGROUND_COLOR
(the numbers correspond to the order of their appearance). Consider building your sequence manually in case you want to use a RGB value instead of an index into the ANSI Color-Table.- Parameters:
aAnsiEscapeCodes
- The Escape-Codes to be included in the Escape-Code sequence.- Returns:
- The correctly generated Escape-Code sequence directly printable
to
System.out
.
-
toEscapedSequence
Makes the provided Escape-Sequence printable by replacing theESCAPE
code with a printable char sequence. This means that the Escape-Sequence is disabled so that it will be printed out as plain text.- Parameters:
aEscapeSequence
- The Escape-Sequence to be printed out as plain text.- Returns:
- The plain text representation of the given Escape-Sequence.
-
toEscapedSequenceRegions
Retrieves a list of regions (begin index, end index ) with ANSI escape codes. The begin index is being included and the end index is being excluded by the returned regions. -
toUnescapedString
Removes any ANSI escape codes from the providedString
. -
toUnescapedLength
-
toLength
Returns the length of the text, considering whether the text is expected to have ANSI escape codes not considered to be part of the length.- Parameters:
aText
- The text for which to get the length.hasAnsiEscapeCodes
- Whether to take any (non printable) ANSI escape codes into account which would, when not being considered, cause wrong results.- Returns:
- The according print length.
-
toEscaped
Returns the escaped ANSI Escape-Code to be printable without triggering the actual ANSI escape commands.- Returns:
- The escaped ANSI Escape-Code.
-