Class WinSysTerminal
java.lang.Object
org.aesh.terminal.tty.impl.AbstractTerminal
org.aesh.terminal.tty.impl.WinSysTerminal
- All Implemented Interfaces:
Closeable, AutoCloseable, org.aesh.terminal.Terminal
Windows system terminal implementation using native console API via JNI.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.aesh.terminal.Terminal
org.aesh.terminal.Terminal.SignalHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.aesh.terminal.AttributesTerminal attributes.protected final ShutdownHooks.TaskShutdown hook task for cleanup.protected static final intEnable echo input mode.protected static final intEnable insert mode.protected static final intEnable line input mode.protected static final intEnable mouse input mode.protected static final intEnable processed input mode.protected static final intEnable quick edit mode.protected static final intEnable virtual terminal input (VT sequences for special keys and mouse).protected static final intEnable window input mode.protected final InputStreamTerminal input stream.Map of native signal handlers.protected intOriginal console input mode, saved for restoration on close.protected final OutputStreamTerminal output stream.protected final ThreadInput pump thread.protected final OutputStreamSlave input pipe.protected booleanWhether VT input mode was successfully enabled on the input handle.protected final PrintWriterPrint writer for output.Fields inherited from interface org.aesh.terminal.Terminal
READ_EXPIRED -
Constructor Summary
ConstructorsConstructorDescriptionWinSysTerminal(String name, boolean nativeSignals) Create a new Windows system terminal with the specified name.WinSysTerminal(String name, boolean nativeSignals, org.aesh.terminal.Terminal.SignalHandler signalHandler) Create a new Windows system terminal with custom signal handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected intctrl(char key) Convert a character to its control code equivalent.org.aesh.terminal.AttributesConsumer<int[]> protected StringGet the console encoding based on the console output code page.protected intGet the current console mode.protected intGet the console output code page.protected StringgetEscapeSequence(short keyCode) Get the escape sequence for a Windows virtual key code.Consumer<org.aesh.terminal.tty.MouseEvent> Get the current mouse handler.protected StringgetSequence(org.aesh.terminal.tty.Capability cap) Get the terminal sequence for a capability.org.aesh.terminal.tty.SizegetSize()protected voidhandleDefaultSignal(org.aesh.terminal.tty.Signal signal) Handles the default behavior for a signal when no custom handler is registered.input()static booleanCheck if virtual terminal mode is supported.output()intpeek(long timeoutMs) protected voidpump()Pump thread that reads console input and processes it.intread(byte[] b, int off, int len, long timeoutMs) intread(long timeoutMs) protected byte[]Read console input from the Windows console.voidsetAttributes(org.aesh.terminal.Attributes attr) Set terminal attributes.protected voidsetConsoleMode(int mode) Set the console mode.voidsetMouseHandler(Consumer<org.aesh.terminal.tty.MouseEvent> handler) Set the mouse event handler.voidsetSize(org.aesh.terminal.tty.Size size) Set the terminal size.booleanWhether this terminal advertises non-blocking read/peek to callers.protected booleanWhether the pump can use WaitForSingleObject with timeout.writer()Get the print writer for output.Methods inherited from class AbstractTerminal
device, echo, echo, echoSignal, getName, getType, handle, raise
-
Field Details
-
ENABLE_PROCESSED_INPUT
protected static final int ENABLE_PROCESSED_INPUTEnable processed input mode.- See Also:
-
ENABLE_LINE_INPUT
protected static final int ENABLE_LINE_INPUTEnable line input mode.- See Also:
-
ENABLE_ECHO_INPUT
protected static final int ENABLE_ECHO_INPUTEnable echo input mode.- See Also:
-
ENABLE_WINDOW_INPUT
protected static final int ENABLE_WINDOW_INPUTEnable window input mode.- See Also:
-
ENABLE_MOUSE_INPUT
protected static final int ENABLE_MOUSE_INPUTEnable mouse input mode.- See Also:
-
ENABLE_INSERT_MODE
protected static final int ENABLE_INSERT_MODEEnable insert mode.- See Also:
-
ENABLE_QUICK_EDIT_MODE
protected static final int ENABLE_QUICK_EDIT_MODEEnable quick edit mode.- See Also:
-
ENABLE_VIRTUAL_TERMINAL_INPUT
protected static final int ENABLE_VIRTUAL_TERMINAL_INPUTEnable virtual terminal input (VT sequences for special keys and mouse).- See Also:
-
slaveInputPipe
Slave input pipe. -
input
Terminal input stream. -
output
Terminal output stream. -
writer
Print writer for output. -
nativeHandlers
-
closer
Shutdown hook task for cleanup. -
attributes
protected final org.aesh.terminal.Attributes attributesTerminal attributes. -
pump
Input pump thread. -
vtInputEnabled
protected boolean vtInputEnabledWhether VT input mode was successfully enabled on the input handle. -
originalInputMode
protected int originalInputModeOriginal console input mode, saved for restoration on close.
-
-
Constructor Details
-
WinSysTerminal
Create a new Windows system terminal with the specified name.- Parameters:
name- the terminal namenativeSignals- whether to use native signal handling- Throws:
IOException- if an I/O error occurs
-
WinSysTerminal
public WinSysTerminal(String name, boolean nativeSignals, org.aesh.terminal.Terminal.SignalHandler signalHandler) throws IOException Create a new Windows system terminal with custom signal handler.- Parameters:
name- the terminal namenativeSignals- whether to use native signal handlingsignalHandler- the signal handler to use- Throws:
IOException- if an I/O error occurs
-
-
Method Details
-
getConsoleOutputCP
protected int getConsoleOutputCP()Get the console output code page.- Returns:
- the code page number
-
getConsoleMode
protected int getConsoleMode()Get the current console mode.- Returns:
- the console mode flags
-
setConsoleMode
protected void setConsoleMode(int mode) Set the console mode.- Parameters:
mode- the mode flags to set
-
getSize
public org.aesh.terminal.tty.Size getSize() -
readConsoleInput
protected byte[] readConsoleInput()Read console input from the Windows console.- Returns:
- the input bytes
-
setMouseHandler
Set the mouse event handler. Enables/disables ENABLE_MOUSE_INPUT on the console input handle.- Parameters:
handler- the mouse event handler, ornullto disable mouse input
-
getMouseHandler
Get the current mouse handler.- Returns:
- the current mouse event handler, or
nullif none is set
-
isVTSupported
public static boolean isVTSupported()Check if virtual terminal mode is supported.- Returns:
- true if virtual terminal mode is supported
-
getCodePointConsumer
-
handleDefaultSignal
protected void handleDefaultSignal(org.aesh.terminal.tty.Signal signal) Description copied from class:AbstractTerminalHandles the default behavior for a signal when no custom handler is registered. Subclasses can override this method to provide default signal handling behavior.- Overrides:
handleDefaultSignalin classAbstractTerminal- Parameters:
signal- the signal to handle
-
getConsoleEncoding
Get the console encoding based on the console output code page.- Returns:
- the charset name, or null if not supported
-
writer
-
input
-
output
-
getAttributes
public org.aesh.terminal.Attributes getAttributes() -
setAttributes
public void setAttributes(org.aesh.terminal.Attributes attr) Set terminal attributes.- Parameters:
attr- the attributes to set
-
ctrl
protected int ctrl(char key) Convert a character to its control code equivalent.- Parameters:
key- the character- Returns:
- the control code
-
setSize
public void setSize(org.aesh.terminal.tty.Size size) Set the terminal size. Not supported on Windows.- Parameters:
size- the size to set- Throws:
UnsupportedOperationException- always
-
supportsNonBlockingRead
public boolean supportsNonBlockingRead()Whether this terminal advertises non-blocking read/peek to callers.Returns false because Windows peek goes through a PipedInputStream which has pump thread latency — unreliable for timing-sensitive escape sequence disambiguation. The poll-based pump loop uses
supportsNonBlockingWait()directly viaWinConsoleNative.supportsNonBlockingWait(). -
supportsNonBlockingWait
protected boolean supportsNonBlockingWait()Whether the pump can use WaitForSingleObject with timeout. This is separate fromTerminal.supportsNonBlockingRead()which controls whether external callers (Readline) can use peek().- Returns:
trueif the pump can use non-blocking wait
-
read
- Throws:
IOException
-
peek
- Throws:
IOException
-
read
- Throws:
IOException
-
close
public void close() -
getEscapeSequence
Get the escape sequence for a Windows virtual key code.- Parameters:
keyCode- the Windows virtual key code- Returns:
- the escape sequence, or null if not mapped
-
getSequence
Get the terminal sequence for a capability.- Parameters:
cap- the capability- Returns:
- the sequence string, or null if not available
-
pump
protected void pump()Pump thread that reads console input and processes it.On Java 22+ (FFM), uses WaitForSingleObject with a timeout for clean shutdown without needing to close the console handle. On Java 8-21 (JNI), blocks on ReadConsoleInputW.
-