Package org.aesh.terminal
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.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.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<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<TerminalTheme> Get the current theme change handler.default ConnectionWrite a string to the output handler.
-
Method Details
-
device
Device device()Get the device associated with this connection.- Returns:
- type of terminal
-
size
Size size()Get the current terminal size.- Returns:
- terminal 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
Consumer<int[]> stdoutHandler()Handler that's called for all output.- Returns:
- output handler
-
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
Get the signal handler.- Returns:
- handler that's called when a Signal is sent to the terminal
-
setSignalHandler
Specify the signal handler.- Parameters:
handler- signal handler
-
sizeHandler
Get the size handler.- Returns:
- handler that's called when the terminal changes size
-
setSizeHandler
Specify size handler that's called when the terminal changes size.- Parameters:
handler- the size change handler
-
closeHandler
Get the close handler.- Returns:
- handler that's called when the input stream is closed
-
setCloseHandler
Specify handler that's called when the input stream is closed.- Parameters:
closeHandler- handler
-
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
-
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
Attributes attributes()Get the current terminal attributes.- Returns:
- the terminal 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- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Throws:
IOException
-
terminal
Access advanced terminal features: queries, capability detection, semantic output, and mode management.- Returns:
- the terminal features for this connection
-
asWriter
Return aWriterview of this connection. Writes to the returned Writer are forwarded to this connection's output.- Returns:
- a Writer that delegates to this connection
-
asPrintWriter
Return aPrintWriterview of this connection. Useful for formatted output (printf, println, etc.).- Returns:
- a PrintWriter that delegates to this connection
-