Class TerminalConnection

java.lang.Object
org.aesh.terminal.AbstractConnection
org.aesh.terminal.tty.TerminalConnection
All Implemented Interfaces:
Appendable, AutoCloseable, Connection

public class TerminalConnection extends AbstractConnection
Implementation of Connection meant for local terminal connections.
Author:
Stale W. Pedersen
  • 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 charset
      outputCharset - the charset for output encoding, or null to use the default charset
      inputStream - the input stream for the terminal
      outputStream - the output stream for the terminal
      handler - 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 encoding
      inputStream - the input stream for the terminal
      outputStream - the output stream for the terminal
      handler - 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 encoding
      inputStream - the input stream for the terminal
      outputStream - the output stream for the terminal
      Throws:
      IOException - if an I/O error occurs
    • TerminalConnection

      public TerminalConnection() throws IOException
      Creates a new TerminalConnection using system default charset and standard I/O streams.
      Throws:
      IOException - if an I/O error occurs
    • TerminalConnection

      public TerminalConnection(Consumer<Connection> handler) throws IOException
      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(Terminal terminal)
      Creates a new TerminalConnection wrapping an existing Terminal.
      Parameters:
      terminal - the terminal to wrap
  • Method Details

    • openNonBlocking

      public void openNonBlocking()
    • put

      public boolean put(Capability capability, Object... params)
    • attributes

      public Attributes attributes()
      Specified by:
      attributes in interface Connection
      Overrides:
      attributes in class AbstractConnection
    • setAttributes

      public void setAttributes(Attributes attr)
      Specified by:
      setAttributes in interface Connection
      Overrides:
      setAttributes in class AbstractConnection
    • inputEncoding

      public Charset inputEncoding()
    • outputEncoding

      public Charset outputEncoding()
    • supportsAnsi

      public boolean supportsAnsi()
    • openBlocking

      public void openBlocking()
      Opens the Connection stream, this method will block and wait for input.
    • openBlocking

      public void openBlocking(String buffer)
      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 until awake() 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

      public Terminal getTerminal()
      Returns the underlying Terminal instance.
      Returns:
      the terminal
    • device

      public Device device()
    • size

      public Size size()
    • setStdinHandler

      public void setStdinHandler(Consumer<int[]> handler)
      Specified by:
      setStdinHandler in interface Connection
      Overrides:
      setStdinHandler in class AbstractConnection
    • close

      public void close()