Package org.aesh.terminal.http
Class HttpTtyConnection
java.lang.Object
org.aesh.terminal.http.HttpTtyConnection
- All Implemented Interfaces:
AutoCloseable,Connection
A connection to an http client, independent of the protocol, it could be straight WebSockets or
SockJS, etc...
The incoming protocol is based on JSON messages with an "action" field:
init - Client capability reporting (sent on connect)
{
"action": "init",
"type": "xterm-256color",
"colorDepth": "TRUE_COLOR",
"features": ["UNICODE", "CLIPBOARD"],
"cols": 80,
"rows": 24,
"userAgent": "Mozilla/5.0 ..."
}
read - User terminal input
{
"action": "read",
"data": "what the user typed"
}
resize - Terminal size change
{
"action": "resize",
"cols": 120,
"rows": 40
}
- Author:
- Julien Viet, Matej Lazar
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new HTTP TTY connection with default charset (UTF-8) and size (80x24).HttpTtyConnection(Charset charset, Size size) Creates a new HTTP TTY connection with the specified charset and size. -
Method Summary
Modifier and TypeMethodDescriptiondevice()Returns the handler for terminal size change events.Consumer<int[]> Returns the handler for standard input data.Returns the handler for terminal type events.booleanReturns whether the client has sent an init message.longReturns the timestamp of the last access to this connection.voidvoidbooleanput(Capability capability, Object... params) voidsetAttributes(Attributes attr) voidsetCloseHandler(Consumer<Void> closeHandler) voidsetSignalHandler(Consumer<Signal> handler) voidsetSizeHandler(Consumer<Size> handler) Sets the handler for terminal size change events.voidsetStdinHandler(Consumer<int[]> handler) Sets the handler for standard input data.voidsetTerminalTypeHandler(Consumer<String> handler) Sets the handler for terminal type events.size()Consumer<int[]> Returns the standard output handler for writing terminal output.booleanprotected abstract voidwrite(byte[] buffer) Writes raw bytes to the underlying transport.voidwriteToDecoder(String msg) Processes an incoming JSON message from the client and writes it to the decoder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aesh.terminal.Connection
close, close, enterRawMode, getColorCapability, getColorDepth, getCursorPosition, getTerminalType, queryBackgroundColor, queryCursorColor, queryDeviceAttributes, queryForegroundColor, queryImageProtocol, queryOsc, queryOsc, queryPaletteColor, queryPaletteColorIfSupported, queryPrimaryDeviceAttributes, querySecondaryDeviceAttributes, querySupportsOscQueries, queryTerminal, supportsClipboard, supportsColorQuery, supportsOscCode, supportsOscQueries, supportsOscQueries, supportsPaletteQuery, write
-
Field Details
-
DEFAULT_SIZE
Default terminal size (80 columns x 24 rows).
-
-
Constructor Details
-
HttpTtyConnection
public HttpTtyConnection()Creates a new HTTP TTY connection with default charset (UTF-8) and size (80x24). -
HttpTtyConnection
Creates a new HTTP TTY connection with the specified charset and size.- Parameters:
charset- the character encoding for the connectionsize- the initial terminal size
-
-
Method Details
-
isInitialized
public boolean isInitialized()Returns whether the client has sent an init message.- Returns:
- true if the client has initialized the connection
-
outputEncoding
- Specified by:
outputEncodingin interfaceConnection
-
inputEncoding
- Specified by:
inputEncodingin interfaceConnection
-
lastAccessedTime
public long lastAccessedTime()Returns the timestamp of the last access to this connection.- Returns:
- the last accessed time in milliseconds since epoch
-
device
- Specified by:
devicein interfaceConnection
-
write
protected abstract void write(byte[] buffer) Writes raw bytes to the underlying transport.- Parameters:
buffer- the bytes to write
-
writeToDecoder
Processes an incoming JSON message from the client and writes it to the decoder.Handles the following actions:
- init - Client capability reporting (type, colorDepth, features, cols, rows)
- read - Terminal input from the user
- resize - Terminal resize events
- Parameters:
msg- the JSON message from the client
-
getTerminalTypeHandler
Returns the handler for terminal type events.- Returns:
- the terminal type handler, or null if not set
-
setTerminalTypeHandler
Sets the handler for terminal type events.- Parameters:
handler- the handler to invoke when terminal type is received
-
size
- Specified by:
sizein interfaceConnection
-
getSizeHandler
Returns the handler for terminal size change events.- Specified by:
getSizeHandlerin interfaceConnection- Returns:
- the size handler, or null if not set
-
setSizeHandler
Sets the handler for terminal size change events.- Specified by:
setSizeHandlerin interfaceConnection- Parameters:
handler- the handler to invoke when terminal size changes
-
getSignalHandler
- Specified by:
getSignalHandlerin interfaceConnection
-
setSignalHandler
- Specified by:
setSignalHandlerin interfaceConnection
-
getStdinHandler
Returns the handler for standard input data.- Specified by:
getStdinHandlerin interfaceConnection- Returns:
- the stdin handler, or null if not set
-
setStdinHandler
Sets the handler for standard input data.- Specified by:
setStdinHandlerin interfaceConnection- Parameters:
handler- the handler to invoke when input is received
-
stdoutHandler
Returns the standard output handler for writing terminal output.- Specified by:
stdoutHandlerin interfaceConnection- Returns:
- the stdout handler
-
setCloseHandler
- Specified by:
setCloseHandlerin interfaceConnection
-
getCloseHandler
- Specified by:
getCloseHandlerin interfaceConnection
-
openBlocking
public void openBlocking()- Specified by:
openBlockingin interfaceConnection
-
openNonBlocking
public void openNonBlocking()- Specified by:
openNonBlockingin interfaceConnection
-
put
- Specified by:
putin interfaceConnection
-
getAttributes
- Specified by:
getAttributesin interfaceConnection
-
setAttributes
- Specified by:
setAttributesin interfaceConnection
-
supportsAnsi
public boolean supportsAnsi()- Specified by:
supportsAnsiin interfaceConnection
-