Class TerminalConnection
java.lang.Object
org.aesh.terminal.AbstractConnection
org.aesh.terminal.tty.TerminalConnection
- All Implemented Interfaces:
Appendable, AutoCloseable, org.aesh.terminal.Connection
public class TerminalConnection
extends org.aesh.terminal.AbstractConnection
Implementation of Connection meant for local terminal connections.
- Author:
- Stale W. Pedersen
-
Field Summary
Fields inherited from class org.aesh.terminal.AbstractConnection
attributes, closeHandler, eventDecoder, reading, sizeHandler, stdout -
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<org.aesh.terminal.Connection> handler) Creates a new TerminalConnection with the specified charset, streams, and handler.TerminalConnection(Charset inputCharset, Charset outputCharset, InputStream inputStream, OutputStream outputStream, Consumer<org.aesh.terminal.Connection> handler) Creates a new TerminalConnection with the specified charsets, streams, and handler.TerminalConnection(Consumer<org.aesh.terminal.Connection> handler) Creates a new TerminalConnection using system defaults with a connection handler.TerminalConnection(org.aesh.terminal.Terminal terminal) Creates a new TerminalConnection wrapping an existing Terminal. -
Method Summary
Modifier and TypeMethodDescriptionorg.aesh.terminal.Attributesvoidawake()Resumes reading from the terminal input stream after a suspend.voidclose()org.aesh.terminal.tty.ScreenRegionorg.aesh.terminal.Devicedevice()org.aesh.terminal.TerminalReturns the underlying Terminal instance.booleanbooleanReturns 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.voidintpeek(long timeoutMs) voidprintAbove(String text) booleanvoidsetAttributes(org.aesh.terminal.Attributes attr) voidsetCurrentRegion(org.aesh.terminal.tty.ScreenRegion region) voidsetMouseHandler(Consumer<org.aesh.terminal.tty.MouseEvent> handler) voidsetStdinHandler(Consumer<int[]> handler) org.aesh.terminal.tty.Sizesize()org.aesh.terminal.tty.SplitScreenorg.aesh.terminal.tty.SplitScreensplitScreen(double ratio) voidStops reading from the terminal input stream and wakes up any suspended threads.booleanbooleanvoidsuspend()Suspends reading from the terminal input stream.booleanReturns whether the connection is currently suspended.org.aesh.terminal.ConnectionMethods inherited from class org.aesh.terminal.AbstractConnection
closeHandler, focusHandler, getStatusMessages, mouseHandler, printAboveHandler, reading, registerStatusLine, setCloseHandler, setFocusHandler, setPrintAboveHandler, setSignalHandler, setSizeHandler, 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, enterRawMode
-
Constructor Details
-
TerminalConnection
public TerminalConnection(Charset inputCharset, Charset outputCharset, InputStream inputStream, OutputStream outputStream, Consumer<org.aesh.terminal.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<org.aesh.terminal.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
public TerminalConnection(org.aesh.terminal.Terminal terminal) Creates a new TerminalConnection wrapping an existing Terminal.- Parameters:
terminal- the terminal to wrap
-
-
Method Details
-
openNonBlocking
public void openNonBlocking() -
put
-
attributes
public org.aesh.terminal.Attributes attributes()- Specified by:
attributesin interfaceorg.aesh.terminal.Connection- Overrides:
attributesin classorg.aesh.terminal.AbstractConnection
-
setAttributes
public void setAttributes(org.aesh.terminal.Attributes attr) - Specified by:
setAttributesin interfaceorg.aesh.terminal.Connection- Overrides:
setAttributesin classorg.aesh.terminal.AbstractConnection
-
inputEncoding
-
outputEncoding
-
supportsAnsi
public boolean supportsAnsi() -
isInteractive
public boolean isInteractive() -
setMouseHandler
- Specified by:
setMouseHandlerin interfaceorg.aesh.terminal.Connection- Overrides:
setMouseHandlerin classorg.aesh.terminal.AbstractConnection
-
openBlocking
public void openBlocking()Opens the Connection stream, this method will block and wait for input. -
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. -
write
-
printAbove
-
getTerminal
public org.aesh.terminal.Terminal getTerminal()Returns the underlying Terminal instance.- Returns:
- the terminal
-
device
public org.aesh.terminal.Device device() -
size
public org.aesh.terminal.tty.Size size() -
setStdinHandler
- Specified by:
setStdinHandlerin interfaceorg.aesh.terminal.Connection- Overrides:
setStdinHandlerin classorg.aesh.terminal.AbstractConnection
-
supportsNonBlockingRead
public boolean supportsNonBlockingRead() -
peek
- Throws:
IOException
-
splitScreen
public org.aesh.terminal.tty.SplitScreen splitScreen(double ratio) -
splitScreen
public org.aesh.terminal.tty.SplitScreen splitScreen() -
setCurrentRegion
public void setCurrentRegion(org.aesh.terminal.tty.ScreenRegion region) -
currentRegion
public org.aesh.terminal.tty.ScreenRegion currentRegion() -
close
public void close()
-