Package org.aesh.terminal.tty.impl
Class WinConsoleNative
java.lang.Object
org.aesh.terminal.tty.impl.WinConsoleNative
JNI bridge to Windows console API (Kernel32).
Replaces JNA for GraalVM native-image compatibility.
This class provides low-level access to Windows console functions
via JNI. The native library (aesh-console.dll) is loaded
from the system library path or extracted from the JAR at runtime.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConsole mode flag: enable virtual terminal input on input handle.static final intConsole mode flag: enable virtual terminal processing on output handle.static final longInvalid handle sentinel value.static final intEvent type constants matching Windows INPUT_RECORD.EventType.static final intStandard error handle identifier.static final intStandard input handle identifier.static final intStandard output handle identifier.static final intWindow buffer size event type. -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetConsoleMode(long handle) Returns the current console mode for the given handle.static intReturns the console output code page.static int[]getConsoleSize(long handle) Returns the console size as {columns, rows}.static longgetStdHandle(int nStdHandle) Returns the handle for the specified standard device.static int[]readConsoleInputEvent(long handle) Read a console input event (key or window resize).static booleansetConsoleMode(long handle, int mode) Sets the console mode for the given handle.static booleanwriteConsole(long handle, char[] buffer, int length) Writes characters to the console.
-
Field Details
-
STD_INPUT_HANDLE
public static final int STD_INPUT_HANDLEStandard input handle identifier.- See Also:
-
STD_OUTPUT_HANDLE
public static final int STD_OUTPUT_HANDLEStandard output handle identifier.- See Also:
-
STD_ERROR_HANDLE
public static final int STD_ERROR_HANDLEStandard error handle identifier.- See Also:
-
INVALID_HANDLE
public static final long INVALID_HANDLEInvalid handle sentinel value.- See Also:
-
KEY_EVENT
public static final int KEY_EVENTEvent type constants matching Windows INPUT_RECORD.EventType.- See Also:
-
WINDOW_BUFFER_SIZE_EVENT
public static final int WINDOW_BUFFER_SIZE_EVENTWindow buffer size event type.- See Also:
-
ENABLE_VIRTUAL_TERMINAL_PROCESSING
public static final int ENABLE_VIRTUAL_TERMINAL_PROCESSINGConsole mode flag: enable virtual terminal processing on output handle.- See Also:
-
ENABLE_VIRTUAL_TERMINAL_INPUT
public static final int ENABLE_VIRTUAL_TERMINAL_INPUTConsole mode flag: enable virtual terminal input on input handle.- See Also:
-
-
Method Details
-
getStdHandle
public static long getStdHandle(int nStdHandle) Returns the handle for the specified standard device.- Parameters:
nStdHandle- the standard device identifier- Returns:
- the device handle
-
getConsoleMode
public static int getConsoleMode(long handle) Returns the current console mode for the given handle.- Parameters:
handle- the console handle- Returns:
- the console mode flags
-
setConsoleMode
public static boolean setConsoleMode(long handle, int mode) Sets the console mode for the given handle.- Parameters:
handle- the console handlemode- the console mode flags- Returns:
- true if successful
-
getConsoleOutputCP
public static int getConsoleOutputCP()Returns the console output code page.- Returns:
- the output code page identifier
-
getConsoleSize
public static int[] getConsoleSize(long handle) Returns the console size as {columns, rows}.- Parameters:
handle- the console handle- Returns:
- array of {columns, rows}
-
readConsoleInputEvent
public static int[] readConsoleInputEvent(long handle) Read a console input event (key or window resize). Returns int[] where first element is the event type: KEY_EVENT (1): {1, keyDown, repeatCount, vKeyCode, unicodeChar, controlKeyState} WINDOW_BUFFER_SIZE_EVENT (4): {4, width, height} Returns null for other event types or on error.- Parameters:
handle- the console input handle- Returns:
- the event data array, or null
-
writeConsole
public static boolean writeConsole(long handle, char[] buffer, int length) Writes characters to the console.- Parameters:
handle- the console output handlebuffer- the characters to writelength- the number of characters to write- Returns:
- true if successful
-