Class HttpTtyConnection
java.lang.Object
org.aesh.terminal.AbstractConnection
org.aesh.terminal.http.HttpTtyConnection
- All Implemented Interfaces:
Appendable, AutoCloseable, org.aesh.terminal.Connection
public abstract class HttpTtyConnection
extends org.aesh.terminal.AbstractConnection
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
FieldsModifier and TypeFieldDescriptionstatic final org.aesh.terminal.tty.SizeDefault terminal size (80 columns x 24 rows).Fields 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, org.aesh.terminal.tty.Size size) Creates a new HTTP TTY connection with the specified charset and size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()org.aesh.terminal.Devicedevice()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.voidvoidprotected voidPauses reading from the underlying transport.booleanprotected voidResumes reading from the underlying transport after a previouspauseReads()call.voidsetAttributes(org.aesh.terminal.Attributes attr) voidsetTerminalTypeHandler(Consumer<String> handler) Sets the handler for terminal type events.org.aesh.terminal.tty.Sizesize()booleanprotected abstract voidwrite(byte[] buffer) Writes raw bytes to the underlying transport.protected voidwriteSlice(byte[] buf, int off, int len) Writes a slice of a byte buffer 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
attributes, closeHandler, focusHandler, getStatusMessages, mouseHandler, printAboveHandler, reading, registerStatusLine, setCloseHandler, setFocusHandler, setMouseHandler, setPrintAboveHandler, setSignalHandler, setSizeHandler, setStdinHandler, setThemeChangeHandler, signalHandler, sizeHandler, stdinHandler, stdoutHandler, terminal, themeChangeHandlerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aesh.terminal.Connection
append, append, append, asPrintWriter, asWriter, close, currentRegion, enterRawMode, isInteractive, peek, printAbove, setCurrentRegion, splitScreen, splitScreen, supportsNonBlockingRead, write
-
Field Details
-
DEFAULT_SIZE
public static final org.aesh.terminal.tty.Size DEFAULT_SIZEDefault 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
public org.aesh.terminal.Device device() -
write
protected abstract void write(byte[] buffer) Writes raw bytes to the underlying transport.- Parameters:
buffer- the bytes to write
-
writeSlice
protected void writeSlice(byte[] buf, int off, int len) Writes a slice of a byte buffer to the underlying transport.Default implementation copies the slice and delegates to
write(byte[]). Subclasses may override for zero-copy writes when the transport supports offset/length (e.g., Netty ByteBuf).- Parameters:
buf- the source bufferoff- the start offsetlen- the number of bytes to write
-
pauseReads
protected void pauseReads()Pauses reading from the underlying transport. Used for backpressure when the processing queue is full.Default implementation is a no-op. Subclasses with transport-level read control should override this.
-
resumeReads
protected void resumeReads()Resumes reading from the underlying transport after a previouspauseReads()call. -
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
-
setTerminalTypeHandler
-
size
public org.aesh.terminal.tty.Size size() -
close
public void close() -
openBlocking
public void openBlocking() -
openNonBlocking
public void openNonBlocking() -
put
-
setAttributes
public void setAttributes(org.aesh.terminal.Attributes attr) - Specified by:
setAttributesin interfaceorg.aesh.terminal.Connection- Overrides:
setAttributesin classorg.aesh.terminal.AbstractConnection
-
supportsAnsi
public boolean supportsAnsi()
-