Class TerminalConnection

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

public class TerminalConnection extends Object implements Connection
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()
      Specified by:
      openNonBlocking in interface Connection
    • put

      public boolean put(Capability capability, Object... params)
      Specified by:
      put in interface Connection
    • getAttributes

      public Attributes getAttributes()
      Specified by:
      getAttributes in interface Connection
    • setAttributes

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

      public Charset inputEncoding()
      Specified by:
      inputEncoding in interface Connection
    • outputEncoding

      public Charset outputEncoding()
      Specified by:
      outputEncoding in interface Connection
    • supportsAnsi

      public boolean supportsAnsi()
      Specified by:
      supportsAnsi in interface Connection
    • openBlocking

      public void openBlocking()
      Opens the Connection stream, this method will block and wait for input.
      Specified by:
      openBlocking in interface Connection
    • 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()
      Specified by:
      device in interface Connection
    • size

      public Size size()
      Specified by:
      size in interface Connection
    • getSizeHandler

      public Consumer<Size> getSizeHandler()
      Specified by:
      getSizeHandler in interface Connection
    • setSizeHandler

      public void setSizeHandler(Consumer<Size> handler)
      Specified by:
      setSizeHandler in interface Connection
    • getSignalHandler

      public Consumer<Signal> getSignalHandler()
      Specified by:
      getSignalHandler in interface Connection
    • setSignalHandler

      public void setSignalHandler(Consumer<Signal> handler)
      Specified by:
      setSignalHandler in interface Connection
    • getStdinHandler

      public Consumer<int[]> getStdinHandler()
      Specified by:
      getStdinHandler in interface Connection
    • setStdinHandler

      public void setStdinHandler(Consumer<int[]> handler)
      Specified by:
      setStdinHandler in interface Connection
    • stdoutHandler

      public Consumer<int[]> stdoutHandler()
      Specified by:
      stdoutHandler in interface Connection
    • setCloseHandler

      public void setCloseHandler(Consumer<Void> closeHandler)
      Specified by:
      setCloseHandler in interface Connection
    • getCloseHandler

      public Consumer<Void> getCloseHandler()
      Specified by:
      getCloseHandler in interface Connection
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Connection