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 extended flags (required to disable ENABLE_QUICK_EDIT_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 window input mode.protected final InputStreamTerminal input stream.protected booleanWhether mouse input is currently enabled.Map of native signal handlers.protected final OutputStreamTerminal output stream.protected final ThreadInput pump thread.protected final OutputStreamSlave input pipe.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.protected booleanEnables virtual terminal processing on the output handle so ANSI escape sequences render.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 intGet the current console output mode.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()protected booleanWhether console output goes through WriteConsoleW (UTF-16, codepage-independent) rather than the Encoder byte stream.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.protected voidsetConsumeCP(boolean consumeCP) Sets whether console output goes through the native WriteConsoleW path.voidsetMouseHandler(Consumer<org.aesh.terminal.tty.MouseEvent> handler) Set the mouse event handler.protected voidsetOutputConsoleMode(int mode) Set the console output mode.voidsetSize(org.aesh.terminal.tty.Size size) Set the terminal size.booleanWhether this terminal advertises non-blocking read/peek to callers.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_EXTENDED_FLAGS
protected static final int ENABLE_EXTENDED_FLAGSEnable extended flags (required to disable ENABLE_QUICK_EDIT_MODE).- 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. -
mouseInputEnabled
protected boolean mouseInputEnabledWhether mouse input is currently enabled.
-
-
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
-
enableVTOutput
protected boolean enableVTOutput()Enables virtual terminal processing on the output handle so ANSI escape sequences render. Independent of output transport selection.- Returns:
- true if VT processing was enabled
-
isOutputConsoleValid
protected boolean isOutputConsoleValid()Whether console output goes through WriteConsoleW (UTF-16, codepage-independent) rather than the Encoder byte stream.- Returns:
- true when the output handle is a real console
-
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
-
getOutputConsoleMode
protected int getOutputConsoleMode()Get the current console output mode.- Returns:
- the output console mode flags
-
setOutputConsoleMode
protected void setOutputConsoleMode(int mode) Set the console output 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
-
setConsumeCP
protected void setConsumeCP(boolean consumeCP) Sets whether console output goes through the native WriteConsoleW path. Used by subclasses that enable output features after construction.- Parameters:
consumeCP- true to write via WriteConsoleW, false for the byte stream
-
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 internal pump loop always uses WaitForSingleObject with a timeout instead.
-
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.Uses WaitForSingleObject with a timeout so the loop naturally yields control on each timeout, enabling clean shutdown when
closingis set — without needing to close the console handle or inject events. After the first event arrives, drains all pending events before flushing the pipe. This ensures multi-byte sequences (e.g., escape sequences for arrow keys) arrive at EventDecoder as complete chunks rather than byte-by-byte.
-