public class ConsoleHelper
extends java.lang.Object
The default colors are white foreground and black background or other currently used by OS console terminal re-definitions.
Modifier and Type | Field and Description |
---|---|
private static ConsoleHelper |
instance |
static boolean |
isColorEnabled
This flag is true if the system property "console.color" has been set.
|
Modifier | Constructor and Description |
---|---|
private |
ConsoleHelper()
Default empty constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addArrayNative(int[] chars,
int[] attrs,
int[] colors,
int cursorX,
int cursorY)
Perform a bulk output operation for the whole screen at once with
output masking when desired.
|
void |
addStringNative(byte[] str,
int len,
int attrib,
int colorpair)
Add a string to the virtual terminal at the current cursor position.
|
void |
beep()
Beeps the tone on the terminal.
|
void |
clear()
Clears the current console screen.
|
static int |
getACSchar(int index)
This method is used for getting the line-drawing special characters from underlying native
layer.
|
static int |
getAttribute(int index)
This method is used for getting the attributes from underlying native layer.
|
static ConsoleHelper |
getDefaultConsoleHelper()
Access the instance of the console helper.
|
int |
getScreenColumnsNative()
Gets the number of columns on the screen.
|
int |
getScreenRowsNative()
Gets the number of rows on the screen.
|
static java.lang.String |
getTermType()
Gets the terminal type reported by console native backend.
|
int |
getx()
Get X coordinate of the cursor.
|
int |
gety()
Get Y coordinate of the cursor.
|
boolean |
hasColors()
Check if the terminal is able to display colors or not.
|
static void |
initChui()
Initialize the native layer.
|
private static void |
initConsole()
This method performs console initialization on the native side.
|
int |
readKey()
This method reads the key from keyboard by the special reading thread.
|
void |
resetMode()
Reset terminal settings.
|
void |
resume()
Re-activates the console mode after ending of the previous suspension state.
|
boolean |
setCursorNative(int x,
int y)
Set absolute cursor position
|
boolean |
setCursorStatus(boolean on)
Set the cursor visibility on or off.
|
static void |
setTermType(java.lang.String name)
Sets the terminal type used by console backend.
|
void |
suspend()
Save the current state of the console mode and switch to TTY mode temporarily.
|
void |
syncNative()
Synchronizes the state of the console buffers with native terminal window.
|
private static ConsoleHelper instance
public static final boolean isColorEnabled
public static void initChui()
public static ConsoleHelper getDefaultConsoleHelper()
public static int getACSchar(int index)
index
- The index of the character to return.public static int getAttribute(int index)
index
- The index of the attribute to return.private static void initConsole()
public void addArrayNative(int[] chars, int[] attrs, int[] colors, int cursorX, int cursorY)
The specified array safe for use with characters that are UNICODE
encoded which are also outside of the 7-bit ASCII range. Such
characters are passed through to the native layer directly and are
not converted to a natively encoded form. This could be provided
but since one of the primary uses of this method is for drawing
characters (e.g. ACS_HLINE
) which are encoded using the
full 32-bits, any attempt to convert these into a single byte native
encoding would lose data.
Because of the above limitation, DO NOT USE THIS FOR OUTPUT OF USER DATA THAT COULD CONTAIN DATA OUTSIDE OF THE 7-bit ASCII RANGE.
chars
- The array of characters to output. The array is supposed
to provide an item per every screen position.
This item is either -1 if this position is masked or a code
which goes directly to ncurses.attrs
- The array of attributes to output. The array is supposed
to provide an item per every screen position.
The array must be of the same length as the chars array.colors
- The array of colors to output. The array is supposed
to provide an item per every screen position.
The item value of -1 denotes a default terminal color.
The array must be of the same length as the chars array.cursorX
- final cursor position, columncursorY
- final cursor position, rowpublic void addStringNative(byte[] str, int len, int attrib, int colorpair)
str
- The array of characters to output.len
- The lenght of the string to draw in characters.attrib
- The attribute to be used while drawing.colorpair
- The color value to be used while drawing.public void beep()
public void clear()
public int getScreenColumnsNative()
public int getScreenRowsNative()
public boolean hasColors()
true
if display is color capable, false
otherwise.public boolean setCursorNative(int x, int y)
x
- New X coordinate of the cursor.y
- New Y coordinate of the cursor.true
if cursor positioning succeeded.public void syncNative()
public static void setTermType(java.lang.String name)
name
- The new terminal type (must not be null
).public static java.lang.String getTermType()
public boolean setCursorStatus(boolean on) throws java.lang.IllegalStateException
setCursorNative(int, int)
and used normally. This
method only affects the visibility of the cursor.on
- When true
the cursor will become visible, when
false
the cursor will become invisible.true
means visible).java.lang.IllegalStateException
public int readKey()
public int getx()
public int gety()
public void resume()
public void suspend()
public void resetMode()