Package org.aesh.terminal.http
Class HttpTtyConnection
java.lang.Object
org.aesh.terminal.AbstractConnection
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
FieldsFields inherited from class org.aesh.terminal.AbstractConnection
attributes, closeHandler, eventDecoder, reading, sizeHandler, stdout -
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 TypeMethodDescriptionvoidclose()device()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) voidsetTerminalTypeHandler(Consumer<String> handler) Sets the handler for terminal type events.size()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 org.aesh.terminal.AbstractConnection
getAttributes, getCloseHandler, getSignalHandler, getSizeHandler, getStdinHandler, getThemeChangeHandler, reading, setCloseHandler, setSignalHandler, setSizeHandler, setStdinHandler, setThemeChangeHandler, stdoutHandlerMethods 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, disableGraphemeClusterMode, disableSynchronizedOutput, disableThemeChangeNotification, enableGraphemeClusterMode, enableSynchronizedOutput, enableThemeChangeNotification, enableThemeChangeNotification, enterRawMode, getColorCapability, getColorDepth, getCursorPosition, getTerminalType, queryAnsi16Colors, queryBackgroundColor, queryBatchOsc, queryColorCapability, queryColors, queryCursorColor, queryDeviceAttributes, queryForegroundColor, queryGraphemeClusterMode, queryImageProtocol, queryOsc, queryOsc, queryPaletteColor, queryPaletteColorIfSupported, queryPaletteColors, queryPrimaryDeviceAttributes, querySecondaryDeviceAttributes, querySupportsOscQueries, querySynchronizedOutput, queryTerminal, queryThemeMode, queryWithResponseBuffering, supportsClipboard, supportsColorQuery, supportsGraphemeClusterMode, supportsHyperlinks, supportsOscCode, supportsOscQueries, supportsOscQueries, supportsPaletteQuery, supportsShellIntegration, supportsSynchronizedOutput, supportsThemeQuery, write, writeCommandFinished, writeCommandFinished, writeCommandStart, writeHyperlink, writeHyperlink, writePromptEnd, writePromptStart
-
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
-
inputEncoding
-
lastAccessedTime
public long lastAccessedTime()Returns the timestamp of the last access to this connection.- Returns:
- the last accessed time in milliseconds since epoch
-
device
-
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
-
close
public void close() -
openBlocking
public void openBlocking() -
openNonBlocking
public void openNonBlocking() -
put
-
setAttributes
- Specified by:
setAttributesin interfaceConnection- Overrides:
setAttributesin classAbstractConnection
-
supportsAnsi
public boolean supportsAnsi()
-