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

    Constructors
    Constructor
    Description
    Creates 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 Type
    Method
    Description
    org.aesh.terminal.Attributes
     
    void
    Resumes reading from the terminal input stream after a suspend.
    void
     
    org.aesh.terminal.tty.ScreenRegion
     
    org.aesh.terminal.Device
     
    org.aesh.terminal.Terminal
    Returns the underlying Terminal instance.
     
    boolean
     
    boolean
    Returns whether the connection is currently reading from the input stream.
    void
    Opens the Connection stream, this method will block and wait for input.
    void
    Opens the Connection stream with an initial buffer.
    void
     
     
    int
    peek(long timeoutMs)
     
    void
     
    boolean
    put(org.aesh.terminal.tty.Capability capability, Object... params)
     
    void
    setAttributes(org.aesh.terminal.Attributes attr)
     
    void
    setCurrentRegion(org.aesh.terminal.tty.ScreenRegion region)
     
    void
    setMouseHandler(Consumer<org.aesh.terminal.tty.MouseEvent> handler)
     
    void
    setStdinHandler(Consumer<int[]> handler)
     
    org.aesh.terminal.tty.Size
     
    org.aesh.terminal.tty.SplitScreen
     
    org.aesh.terminal.tty.SplitScreen
    splitScreen(double ratio)
     
    void
    Stops reading from the terminal input stream and wakes up any suspended threads.
    boolean
     
    boolean
     
    void
    Suspends reading from the terminal input stream.
    boolean
    Returns whether the connection is currently suspended.
    org.aesh.terminal.Connection
     

    Methods 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, themeChangeHandler

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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 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<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 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<org.aesh.terminal.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(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

      public boolean put(org.aesh.terminal.tty.Capability capability, Object... params)
    • attributes

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

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

      public Charset inputEncoding()
    • outputEncoding

      public Charset outputEncoding()
    • supportsAnsi

      public boolean supportsAnsi()
    • isInteractive

      public boolean isInteractive()
    • setMouseHandler

      public void setMouseHandler(Consumer<org.aesh.terminal.tty.MouseEvent> handler)
      Specified by:
      setMouseHandler in interface org.aesh.terminal.Connection
      Overrides:
      setMouseHandler in class org.aesh.terminal.AbstractConnection
    • 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.
    • write

      public org.aesh.terminal.Connection write(String s)
    • printAbove

      public void printAbove(String text)
    • 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

      public void setStdinHandler(Consumer<int[]> handler)
      Specified by:
      setStdinHandler in interface org.aesh.terminal.Connection
      Overrides:
      setStdinHandler in class org.aesh.terminal.AbstractConnection
    • supportsNonBlockingRead

      public boolean supportsNonBlockingRead()
    • peek

      public int peek(long timeoutMs) throws IOException
      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()