Interface Connection
- All Superinterfaces:
Appendable, AutoCloseable
- All Known Implementing Classes:
AbstractConnection
Represent a connection to either a local/direct/remote Terminal.
This interface provides core I/O operations: input/output handlers, encoding, lifecycle (open/close), and terminal state (attributes, size).
Advanced terminal features (queries, capability detection, semantic output,
mode toggles) are accessible via terminal(), which returns a
TerminalFeatures object.
- Author:
- Ståle W. Pedersen
-
Method Summary
Modifier and TypeMethodDescriptiondefault Appendableappend(char c) default Appendableappend(CharSequence csq) default Appendableappend(CharSequence csq, int start, int end) default PrintWriterReturn aPrintWriterview of this connection.default WriterasWriter()Return aWriterview of this connection.Get the current terminal attributes.voidclose()Stop reading from the input stream.default voidclose(int exit) Close the connection with an exit code.Get the close handler.device()Get the device associated with this connection.default AttributesEnter raw mode for the terminal.Get the input character encoding.default Consumer<MouseEvent> Get the current mouse event handler.voidStart reading from the input stream using the current thread.voidStart reading from the input stream in a separate thread.Get the output character encoding.booleanput(Capability capability, Object... params) Specify terminal settings.default booleanreading()Check if the connection is actively reading from the input stream.voidsetAttributes(Attributes attr) Set the terminal attributes.voidsetCloseHandler(Consumer<Void> closeHandler) Specify handler that's called when the input stream is closed.default voidsetMouseHandler(Consumer<MouseEvent> handler) Set a handler to be called when mouse events are received.voidsetSignalHandler(Consumer<Signal> handler) Specify the signal handler.voidsetSizeHandler(Consumer<Size> handler) Specify size handler that's called when the terminal changes size.voidsetStdinHandler(Consumer<int[]> handler) Set the standard input handler.default voidsetThemeChangeHandler(Consumer<org.aesh.terminal.detect.TerminalTheme> handler) Set a handler to be called when the terminal's theme changes.Get the signal handler.size()Get the current terminal size.Get the size handler.Consumer<int[]> Get the standard input handler.Consumer<int[]> Handler that's called for all output.booleanCheck if this terminal supports ANSI escape sequences.default TerminalFeaturesterminal()Access advanced terminal features: queries, capability detection, semantic output, and mode management.default Consumer<org.aesh.terminal.detect.TerminalTheme> Get the current theme change handler.default ConnectionWrite a string to the output handler.
-
Method Details
-
device
-
size
-
stdinHandler
Consumer<int[]> stdinHandler()Get the standard input handler.- Returns:
- the stdin handler that processes input as code point arrays
-
setStdinHandler
Set the standard input handler.- Parameters:
handler- the handler to process input as code point arrays
-
stdoutHandler
-
write
Write a string to the output handler. When the stdout handler is an Encoder, this uses a fast path that encodes the String directly to bytes without an intermediate int[] allocation.- Parameters:
s- string- Returns:
- this connection
-
put
Specify terminal settings.- Parameters:
capability- capabilityparams- parameters- Returns:
- true if the terminal accepted the settings
-
signalHandler
-
setSignalHandler
-
sizeHandler
-
setSizeHandler
-
closeHandler
-
setCloseHandler
-
setThemeChangeHandler
Set a handler to be called when the terminal's theme changes.- Parameters:
handler- the handler to invoke with the new theme, or null to remove
-
themeChangeHandler
Get the current theme change handler.- Returns:
- the theme change handler, or null if not set
-
setMouseHandler
Set a handler to be called when mouse events are received.Mouse tracking must be explicitly enabled via
MouseTrackingfor the terminal to send mouse events.- Parameters:
handler- the handler to invoke with mouse events, or null to remove- See Also:
-
mouseHandler
Get the current mouse event handler.- Returns:
- the mouse handler, or null if not set
-
openBlocking
void openBlocking()Start reading from the input stream using the current thread. The current thread will be blocked while reading/waiting to read from the stream. -
openNonBlocking
void openNonBlocking()Start reading from the input stream in a separate thread. The current thread will continue. -
reading
default boolean reading()Check if the connection is actively reading from the input stream.- Returns:
- true if the connection is actively reading input
-
close
void close()Stop reading from the input stream. The stream will be closed and cleanup methods will be called. Eg for terminals they will be restored to their original settings.- Specified by:
closein interfaceAutoCloseable
-
close
default void close(int exit) Close the connection with an exit code.- Parameters:
exit- the exit code
-
attributes
-
setAttributes
Set the terminal attributes.- Parameters:
attr- the attributes to set
-
enterRawMode
Enter raw mode for the terminal.In raw mode, input is not line-buffered, echo is disabled, and special character processing is turned off.
- Returns:
- the previous terminal attributes (to restore later)
-
supportsAnsi
boolean supportsAnsi()Check if this terminal supports ANSI escape sequences.- Returns:
- true if ANSI is supported, false otherwise
-
inputEncoding
Charset inputEncoding()Get the input character encoding.- Returns:
- the charset used for input encoding
-
outputEncoding
Charset outputEncoding()Get the output character encoding.- Returns:
- the charset used for output encoding
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
terminal
Access advanced terminal features: queries, capability detection, semantic output, and mode management.- Returns:
- the terminal features for this connection
-
asWriter
-
asPrintWriter
Return aPrintWriterview of this connection. Useful for formatted output (printf, println, etc.).- Returns:
- a PrintWriter that delegates to this connection
-