Package org.aesh.terminal.tty
Class TerminalConnection
java.lang.Object
org.aesh.terminal.tty.TerminalConnection
- All Implemented Interfaces:
AutoCloseable,Connection
Implementation of Connection meant for local terminal connections.
- Author:
- Stale W. Pedersen
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TerminalConnection using system default charset and standard I/O streams.TerminalConnection(Charset charset, InputStream inputStream, OutputStream outputStream) Creates a new TerminalConnection with the specified charset and streams.TerminalConnection(Charset charset, InputStream inputStream, OutputStream outputStream, Consumer<Connection> handler) Creates a new TerminalConnection with the specified charset, streams, and handler.TerminalConnection(Charset inputCharset, Charset outputCharset, InputStream inputStream, OutputStream outputStream, Consumer<Connection> handler) Creates a new TerminalConnection with the specified charsets, streams, and handler.TerminalConnection(Consumer<Connection> handler) Creates a new TerminalConnection using system defaults with a connection handler.TerminalConnection(Terminal terminal) Creates a new TerminalConnection wrapping an existing Terminal. -
Method Summary
Modifier and TypeMethodDescriptionvoidawake()Resumes reading from the terminal input stream after a suspend.voidclose()device()Consumer<int[]> Returns the underlying Terminal instance.booleanReturns whether the connection is currently reading from the input stream.voidOpens the Connection stream, this method will block and wait for input.voidopenBlocking(String buffer) Opens the Connection stream with an initial buffer.voidbooleanput(Capability capability, Object... params) voidsetAttributes(Attributes attr) voidsetCloseHandler(Consumer<Void> closeHandler) voidsetSignalHandler(Consumer<Signal> handler) voidsetSizeHandler(Consumer<Size> handler) voidsetStdinHandler(Consumer<int[]> handler) size()Consumer<int[]> voidStops reading from the terminal input stream and wakes up any suspended threads.booleanvoidsuspend()Suspends reading from the terminal input stream.booleanReturns whether the connection is currently suspended.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, enterRawMode, getColorCapability, getColorDepth, getCursorPosition, queryTerminal, supportsOscQueries, write
-
Constructor Details
-
TerminalConnection
public TerminalConnection(Charset inputCharset, Charset outputCharset, InputStream inputStream, OutputStream outputStream, Consumer<Connection> handler) throws IOException Creates a new TerminalConnection with the specified charsets, streams, and handler.- Parameters:
inputCharset- the charset for input encoding, or null to use the default charsetoutputCharset- the charset for output encoding, or null to use the default charsetinputStream- the input stream for the terminaloutputStream- the output stream for the terminalhandler- the connection handler to be called when the connection is initialized- Throws:
IOException- if an I/O error occurs
-
TerminalConnection
public TerminalConnection(Charset charset, InputStream inputStream, OutputStream outputStream, Consumer<Connection> handler) throws IOException Creates a new TerminalConnection with the specified charset, streams, and handler.- Parameters:
charset- the charset for both input and output encodinginputStream- the input stream for the terminaloutputStream- the output stream for the terminalhandler- the connection handler to be called when the connection is initialized- Throws:
IOException- if an I/O error occurs
-
TerminalConnection
public TerminalConnection(Charset charset, InputStream inputStream, OutputStream outputStream) throws IOException Creates a new TerminalConnection with the specified charset and streams.- Parameters:
charset- the charset for both input and output encodinginputStream- the input stream for the terminaloutputStream- the output stream for the terminal- Throws:
IOException- if an I/O error occurs
-
TerminalConnection
Creates a new TerminalConnection using system default charset and standard I/O streams.- Throws:
IOException- if an I/O error occurs
-
TerminalConnection
Creates a new TerminalConnection using system defaults with a connection handler.- Parameters:
handler- the connection handler to be called when the connection is initialized- Throws:
IOException- if an I/O error occurs
-
TerminalConnection
Creates a new TerminalConnection wrapping an existing Terminal.- Parameters:
terminal- the terminal to wrap
-
-
Method Details
-
openNonBlocking
public void openNonBlocking()- Specified by:
openNonBlockingin interfaceConnection
-
put
- Specified by:
putin interfaceConnection
-
getAttributes
- Specified by:
getAttributesin interfaceConnection
-
setAttributes
- Specified by:
setAttributesin interfaceConnection
-
inputEncoding
- Specified by:
inputEncodingin interfaceConnection
-
outputEncoding
- Specified by:
outputEncodingin interfaceConnection
-
supportsAnsi
public boolean supportsAnsi()- Specified by:
supportsAnsiin interfaceConnection
-
openBlocking
public void openBlocking()Opens the Connection stream, this method will block and wait for input.- Specified by:
openBlockingin interfaceConnection
-
openBlocking
Opens the Connection stream with an initial buffer. This method will block and wait for input.- Parameters:
buffer- initial data to process before reading from the terminal input
-
suspend
public void suspend()Suspends reading from the terminal input stream. The reading thread will wait untilawake()is called. -
awake
public void awake()Resumes reading from the terminal input stream after a suspend. -
suspended
public boolean suspended()Returns whether the connection is currently suspended.- Returns:
- true if the connection is suspended, false otherwise
-
isReading
public boolean isReading()Returns whether the connection is currently reading from the input stream.- Returns:
- true if actively reading, false otherwise
-
stopReading
public void stopReading()Stops reading from the terminal input stream and wakes up any suspended threads. -
getTerminal
Returns the underlying Terminal instance.- Returns:
- the terminal
-
device
- Specified by:
devicein interfaceConnection
-
size
- Specified by:
sizein interfaceConnection
-
getSizeHandler
- Specified by:
getSizeHandlerin interfaceConnection
-
setSizeHandler
- Specified by:
setSizeHandlerin interfaceConnection
-
getSignalHandler
- Specified by:
getSignalHandlerin interfaceConnection
-
setSignalHandler
- Specified by:
setSignalHandlerin interfaceConnection
-
getStdinHandler
- Specified by:
getStdinHandlerin interfaceConnection
-
setStdinHandler
- Specified by:
setStdinHandlerin interfaceConnection
-
stdoutHandler
- Specified by:
stdoutHandlerin interfaceConnection
-
setCloseHandler
- Specified by:
setCloseHandlerin interfaceConnection
-
getCloseHandler
- Specified by:
getCloseHandlerin interfaceConnection
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection
-