Enum X364

java.lang.Object
java.lang.Enum<X364>
org.apache.sis.internal.util.X364
All Implemented Interfaces:
Serializable, Comparable<X364>, java.lang.constant.Constable

public enum X364 extends Enum<X364>
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:
  • Enum Constant Details

    • RESET

      public static final X364 RESET
      Reset all attributes to their default value.
    • NORMAL

      public static final X364 NORMAL
      Normal intensity (not BOLD).
    • BOLD

      public static final X364 BOLD
      Bold intensity.
    • FAINT

      public static final X364 FAINT
      Faint intensity.
    • UNDERLINE

      public static final X364 UNDERLINE
      Single underline.
    • NO_UNDERLINE

      public static final X364 NO_UNDERLINE
      No underline.
    • FOREGROUND_RED

      public static final X364 FOREGROUND_RED
      Red foreground color, normal intensity.
    • FOREGROUND_GREEN

      public static final X364 FOREGROUND_GREEN
      Green foreground color, normal intensity.
    • FOREGROUND_YELLOW

      public static final X364 FOREGROUND_YELLOW
      Yellow foreground color, normal intensity.
    • FOREGROUND_BLUE

      public static final X364 FOREGROUND_BLUE
      Blue foreground color, normal intensity.
    • FOREGROUND_MAGENTA

      public static final X364 FOREGROUND_MAGENTA
      Magenta foreground color, normal intensity.
    • FOREGROUND_CYAN

      public static final X364 FOREGROUND_CYAN
      Cyan foreground color, normal intensity.
    • FOREGROUND_GRAY

      public static final X364 FOREGROUND_GRAY
      Gray foreground color, normal intensity.
    • FOREGROUND_DEFAULT

      public static final X364 FOREGROUND_DEFAULT
      Reset the foreground color.
    • BACKGROUND_RED

      public static final X364 BACKGROUND_RED
      Red background color, normal intensity.
    • BACKGROUND_GREEN

      public static final X364 BACKGROUND_GREEN
      Green background color, normal intensity.
    • BACKGROUND_YELLOW

      public static final X364 BACKGROUND_YELLOW
      Yellow background color, normal intensity.
    • BACKGROUND_BLUE

      public static final X364 BACKGROUND_BLUE
      Blue background color, normal intensity.
    • BACKGROUND_MAGENTA

      public static final X364 BACKGROUND_MAGENTA
      Magenta background color, normal intensity.
    • BACKGROUND_CYAN

      public static final X364 BACKGROUND_CYAN
      Cyan background color, normal intensity.
    • BACKGROUND_GRAY

      public static final X364 BACKGROUND_GRAY
      Gray background color, normal intensity.
    • BACKGROUND_DEFAULT

      public static final X364 BACKGROUND_DEFAULT
      Reset the background color.
  • Field Details

    • NAMED

      private static final X364[] 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 ESCAPE
      The first character of the START escape string.
      See Also:
    • BRACKET

      public static final char BRACKET
      The second character of the START escape string.
      See Also:
    • START

      private static final String START
      The Control Sequence Introducer (CSI). Must be the concatenation of ESCAPE with BRACKET.
      See Also:
    • END

      private static final char END
      The 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 code
      The X3.64 code.
    • sequence

      private transient String sequence
      The X3.64 escape sequence, built when first needed.
    • foreground

      private transient X364 foreground
      Foreground or background flavors of this enum.
    • background

      private transient X364 background
      Foreground or background flavors of this enum.
    • color

      public final String color
      The color name, or null if none.
  • Constructor Details

    • X364

      private X364(byte code, String color)
      Creates a new code.
      Parameters:
      code - the X.364 numerical code.
      color - the color name, or null if none.
    • X364

      private X364(X364 foreground)
      Creates a new background code.
      Parameters:
      foreground - the X.364 code for a foreground color.
  • Method Details

    • values

      public static X364[] 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

      public static X364 valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • foreground

      public X364 foreground()
      Returns the enum for the foreground color.
      Returns:
      the foreground color, or this if this enum is already a foreground color.
    • background

      public X364 background()
      Returns the enum for the background color.
      Returns:
      the background color, or this if this enum is already a background color.
    • sequence

      public String sequence()
      Returns the ANSI escape sequence.
      Returns:
      the ANSI escape sequence.
    • plain

      public static CharSequence plain(CharSequence text, int fromIndex, int toIndex)
      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

      public 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. This is equivalent to CharSequences.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

      public static X364 forColorName(String color) throws IllegalArgumentException
      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()
      Returns true 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 returns false in case of doubt.