Package org.refcodes.runtime
Enum Terminal
- java.lang.Object
-
- java.lang.Enum<Terminal>
-
- org.refcodes.runtime.Terminal
-
public enum Terminal extends java.lang.Enum<Terminal>
Enumeration with the (relevant) terminals as well as interpolated terminal metrics.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getCurrentTerminalHeight()
Determines the current height in characters of the system's terminal in use.static int
getCurrentTerminalWidth()
Determines the current width in characters of the system's terminal in use.static java.lang.String
getLineBreak()
Determines the operating system as ofOperatingSystem.toOperatingSystem()
and in case aOperatingSystem.WINDOWS
is being detected, then \r\n" (CRLF) is returned, else "\n" (LF) is returned.static java.lang.String
getTerminalEncoding()
Determines the encoding of the system (system's console) in use as ofSystem.out
.static int
getTerminalHeight()
Determines the height in characters of the system's terminal in use.static int
getTerminalHeight(int aValidityTimeMillis)
Determines the height in characters of the system's terminal in use.static int
getTerminalWidth()
Determines the width in characters of the system's terminal in use.static int
getTerminalWidth(int aValidityTimeMillis)
Determines the width in characters of the system's terminal in use.static boolean
isAnsiTerminal()
Determines whether ANSI escape sequences are supported by the terminal.static boolean
isAnsiTerminalPreferred()
Determines whether ANSI escape sequences are forced to be supported or not by REFCODES.ORG artifacts.static boolean
isCurrentlyLineBreakRequired(int aRowWidth)
Determines whether wee need an explicit line-break for the given width on the current operating system and used terminal.static boolean
isLineBreakRequired(int aRowWidth)
Determines whether wee need an explicit line-break for the given width on the current operating system and used terminal.static boolean
isLineBreakRequired(int aRowWidth, int aValidityTimeMillis)
Determines whether wee need an explicit line-break for the given width on the current operating system and used terminal.static java.lang.String
toLineBreak(int aRowWidth)
UsesisLineBreakRequired(int)
to retrieve the character sequence required to suffix to a line in order to get a line break without risking any empty lines as of automatic line wrapping.static int
toPreferredTerminalHeight()
Does some calculation to always return a sound console height (never returns -1).static int
toPreferredTerminalWidth()
Does some calculation to always return a sound console width (never returns -1).static Terminal
toTerminal()
Determines the terminal your application is currently in.static Terminal
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static Terminal[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Method Detail
-
values
public static Terminal[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Terminal c : Terminal.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Terminal valueOf(java.lang.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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getCurrentTerminalHeight
public static int getCurrentTerminalHeight()
Determines the current height in characters of the system's terminal in use. This operation is expensive as it always does a full blown height calculation. To be less expensive, either usegetTerminalHeight()
orgetTerminalHeight(int)
.- Returns:
- The height of the terminal in characters or -1 if the height cannot be determined.
-
getCurrentTerminalWidth
public static int getCurrentTerminalWidth()
Determines the current width in characters of the system's terminal in use. This operation is expensive as it always does a full blown width calculation. To be less expensive, either usegetTerminalWidth()
orgetTerminalWidth(int)
.- Returns:
- The height of the terminal in characters or -1 if the height cannot be determined.
-
getLineBreak
public static java.lang.String getLineBreak()
Determines the operating system as ofOperatingSystem.toOperatingSystem()
and in case aOperatingSystem.WINDOWS
is being detected, then \r\n" (CRLF) is returned, else "\n" (LF) is returned. Can be overridden with theSystemProperty.CONSOLE_LINE_BREAK
(java -Dconsole.lineBreak=...
) and theEnvironmentVariable.CONSOLE_LINE_BREAK
("export CONSOLE_LINE_BREAK=...
).- Returns:
- The operating system's specific line break; on Windows it is "\r\n" (CRLF) and on all other operating systems it is "\n" (LF).
-
getTerminalEncoding
public static java.lang.String getTerminalEncoding()
Determines the encoding of the system (system's console) in use as ofSystem.out
.- Returns:
- The encoding (of the console).
-
getTerminalHeight
public static int getTerminalHeight()
Determines the height in characters of the system's terminal in use.- Returns:
- The height of the terminal in characters or -1 if the height cannot be determined.
-
getTerminalHeight
public static int getTerminalHeight(int aValidityTimeMillis)
Determines the height in characters of the system's terminal in use.- Parameters:
aValidityTimeMillis
- The time period till last determination of this value is valid, as determining this value is expensive.- Returns:
- The height of the terminal in characters or -1 if the height cannot be determined.
-
getTerminalWidth
public static int getTerminalWidth()
Determines the width in characters of the system's terminal in use.- Returns:
- The width of the terminal in characters or -1 if the width cannot be determined.
-
getTerminalWidth
public static int getTerminalWidth(int aValidityTimeMillis)
Determines the width in characters of the system's terminal in use.- Parameters:
aValidityTimeMillis
- The time period till last determination of this value is valid, as determining this value is expensive.- Returns:
- The width of the terminal in characters or -1 if the width cannot be determined.
-
isAnsiTerminal
public static boolean isAnsiTerminal()
Determines whether ANSI escape sequences are supported by the terminal.- Returns:
- True in case ANSI escape sequences are supported, else false.
-
isAnsiTerminalPreferred
public static boolean isAnsiTerminalPreferred()
Determines whether ANSI escape sequences are forced to be supported or not by REFCODES.ORG artifacts. This overrulesisAnsiTerminal()
for the REFCODES.ORG artifacts. Various settings such asSystemProperty.CONSOLE_ANSI
and (in this order)EnvironmentVariable.CONSOLE_ANSI
overruleisAnsiTerminal()
.- Returns:
- True in case ANSI escape sequences are forced to be used by REFCODES.ORG artifacts or not.
-
isCurrentlyLineBreakRequired
public static boolean isCurrentlyLineBreakRequired(int aRowWidth)
Determines whether wee need an explicit line-break for the given width on the current operating system and used terminal. E.g. on "win.cmd" we must not use a line-break in case our line is a s long as the console's width. There are some more such cases which this method tries to take into consideration. This operation is expensive as it always does a full blown width calculation. To be less expensive, either useisLineBreakRequired(int)
orisLineBreakRequired(int, int)
.- Parameters:
aRowWidth
- The row width you want to use when printing out to a console.- Returns:
- True in case you should use a line-break.
-
isLineBreakRequired
public static boolean isLineBreakRequired(int aRowWidth)
Determines whether wee need an explicit line-break for the given width on the current operating system and used terminal. E.g. on "win.cmd" we must not use a line-break in case our line is a s long as the console's width. There are some more such cases which this method tries to take into consideration.- Parameters:
aRowWidth
- The row width you want to use when printing out to a console.- Returns:
- True in case you should use a line-break.
-
isLineBreakRequired
public static boolean isLineBreakRequired(int aRowWidth, int aValidityTimeMillis)
Determines whether wee need an explicit line-break for the given width on the current operating system and used terminal. E.g. on "win.cmd" we must not use a line-break in case our line is a s long as the console's width. There are some more such cases which this method tries to take into consideration.- Parameters:
aRowWidth
- The row width you want to use when printing out to a console.aValidityTimeMillis
- The time period till last determination of this value is valid, as determining this value is expensive.- Returns:
- True in case you should use a line-break.
-
toLineBreak
public static java.lang.String toLineBreak(int aRowWidth)
UsesisLineBreakRequired(int)
to retrieve the character sequence required to suffix to a line in order to get a line break without risking any empty lines as of automatic line wrapping. Automatic line wrapping can happen on Windows environment when the console width is reached. A line break would cause a superfluous empty line (ugly).- Parameters:
aRowWidth
- The row width you want to use when printing out to a console.- Returns:
- The system's line break characters when a line break is emphasized or an empty string if no line break sequence is recommended.
-
toPreferredTerminalHeight
public static int toPreferredTerminalHeight()
Does some calculation to always return a sound console height (never returns -1). Anything in the REFCODES.ORG artifacts which is intended to print to the console uses this method to determine some heuristic best console height.- Returns:
- A sound heuristic console height.
-
toPreferredTerminalWidth
public static int toPreferredTerminalWidth()
Does some calculation to always return a sound console width (never returns -1). Anything in the REFCODES.ORG artifacts which is intended to print to the console uses this method to determine some heuristic best console width.- Returns:
- A sound heuristic console width.
-
-