Package org.apache.sis.internal.util
Enum X364
- All Implemented Interfaces:
Serializable
,Comparable<X364>
,java.lang.constant.Constable
A limited set of color and font attributes assignable to characters at formatting time.
Those attributes are used by SIS formatters for providing some syntax coloring,
for example in the
org.apache.sis.io.wkt
package.
This enumeration is restricted to a subset of the ANSI escape codes (a.k.a. ECMA-48, ISO/IEC 6429 and X3.64 standards) because SIS uses them mostly for syntax coloring in console outputs. However, those attributes can also occasionally be used for HTML rendering.
- Since:
- 0.3
- Version:
- 0.7
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionBlue background color, normal intensity.Cyan background color, normal intensity.Reset the background color.Gray background color, normal intensity.Green background color, normal intensity.Magenta background color, normal intensity.Red background color, normal intensity.Yellow background color, normal intensity.Bold intensity.Faint intensity.Blue foreground color, normal intensity.Cyan foreground color, normal intensity.Reset the foreground color.Gray foreground color, normal intensity.Green foreground color, normal intensity.Magenta foreground color, normal intensity.Red foreground color, normal intensity.Yellow foreground color, normal intensity.No underline.Normal intensity (notBOLD
).Reset all attributes to their default value.Single underline. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate X364
Foreground or background flavors of this enum.static final char
The second character of theSTART
escape string.private final byte
The X3.64 code.final String
The color name, ornull
if none.private static final char
The end of escape sequences.static final char
The first character of theSTART
escape string.private X364
Foreground or background flavors of this enum.private static final X364[]
The list of codes having a non-null color name.private String
The X3.64 escape sequence, built when first needed.private static final String
The Control Sequence Introducer (CSI). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the enum for the background color.static X364
forColorName
(String color) Returns the enumeration value for the given color name.Returns the enum for the foreground color.static boolean
Returnstrue
if we think that the operating system supports ANSI sequences.static int
lengthOfPlain
(CharSequence text, int fromIndex, int toIndex) Returns the number of Unicode code points in the given string without the ANSI escape codes.static CharSequence
plain
(CharSequence text, int fromIndex, int toIndex) Removes all escape codes from the given string.sequence()
Returns the ANSI escape sequence.static X364
Returns the enum constant of this type with the specified name.static X364[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
RESET
Reset all attributes to their default value. -
NORMAL
Normal intensity (notBOLD
). -
BOLD
Bold intensity. -
FAINT
Faint intensity. -
UNDERLINE
Single underline. -
NO_UNDERLINE
No underline. -
FOREGROUND_RED
Red foreground color, normal intensity. -
FOREGROUND_GREEN
Green foreground color, normal intensity. -
FOREGROUND_YELLOW
Yellow foreground color, normal intensity. -
FOREGROUND_BLUE
Blue foreground color, normal intensity. -
FOREGROUND_MAGENTA
Magenta foreground color, normal intensity. -
FOREGROUND_CYAN
Cyan foreground color, normal intensity. -
FOREGROUND_GRAY
Gray foreground color, normal intensity. -
FOREGROUND_DEFAULT
Reset the foreground color. -
BACKGROUND_RED
Red background color, normal intensity. -
BACKGROUND_GREEN
Green background color, normal intensity. -
BACKGROUND_YELLOW
Yellow background color, normal intensity. -
BACKGROUND_BLUE
Blue background color, normal intensity. -
BACKGROUND_MAGENTA
Magenta background color, normal intensity. -
BACKGROUND_CYAN
Cyan background color, normal intensity. -
BACKGROUND_GRAY
Gray background color, normal intensity. -
BACKGROUND_DEFAULT
Reset the background color.
-
-
Field Details
-
NAMED
The list of codes having a non-null color name. They are the codes in the range 31 to 37 inclusive.- See Also:
-
ESCAPE
public static final char ESCAPEThe first character of theSTART
escape string.- See Also:
-
BRACKET
public static final char BRACKETThe second character of theSTART
escape string.- See Also:
-
START
- See Also:
-
END
private static final char ENDThe end of escape sequences. Fixed to'm'
for now, but a wider range of letters actually exists for different operations.- See Also:
-
code
private final transient byte codeThe X3.64 code. -
sequence
The X3.64 escape sequence, built when first needed. -
foreground
Foreground or background flavors of this enum. -
background
Foreground or background flavors of this enum. -
color
The color name, ornull
if none.
-
-
Constructor Details
-
X364
Creates a new code.- Parameters:
code
- the X.364 numerical code.color
- the color name, ornull
if none.
-
X364
Creates a new background code.- Parameters:
foreground
- the X.364 code for a foreground color.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- if the argument is null
-
foreground
Returns the enum for the foreground color.- Returns:
- the foreground color, or
this
if this enum is already a foreground color.
-
background
Returns the enum for the background color.- Returns:
- the background color, or
this
if this enum is already a background color.
-
sequence
Returns the ANSI escape sequence.- Returns:
- the ANSI escape sequence.
-
plain
Removes all escape codes from the given string.- Parameters:
text
- the string which may contains escape codes.fromIndex
- the index from which to start the process.toIndex
- the index after the last character to process.- Returns:
- text without the escape codes, or the given
text
reference if it didn't contained any escape codes.
-
lengthOfPlain
Returns the number of Unicode code points in the given string without the ANSI escape codes. This is equivalent toCharSequences.codePointCount(plain(text))
without the cost of creating a temporary string.- Parameters:
text
- the string which may contains escape codes.fromIndex
- the index from which to start the computation.toIndex
- the index after the last character to take in account.- Returns:
- the length of the given string without escape codes.
-
forColorName
Returns the enumeration value for the given color name. The search is case-insensitive.- Parameters:
color
- the color name.- Returns:
- the code for the given color name.
- Throws:
IllegalArgumentException
- if no code has been found for the given color name.
-
isAnsiSupported
public static boolean isAnsiSupported()Returnstrue
if we think that the operating system supports ANSI sequences. This method performs a very naive and rough check. Result is just a hint and may be wrong.This method does not check if a console is attached to the running JVM because the caller may want to write to the standard error stream instead of the standard output stream, in which case the console information is not applicable.
- Returns:
true
if we think that the operating system supports ANSI codes. This method may conservatively returnsfalse
in case of doubt.
-