Class LineDisciplineTerminal

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, Terminal
    Direct Known Subclasses:
    ExternalTerminal

    public class LineDisciplineTerminal
    extends AbstractTerminal
    Abstract terminal with support for line discipline. The Terminal interface represents the slave side of a PTY, but implementations derived from this class will handle both the slave and master side of things. In order to correctly handle line discipline, the terminal needs to read the input in advance in order to raise the signals as fast as possible. For example, when the user hits Ctrl+C, we can't wait until the application consumes all the read events. The same applies to echoing, when enabled, as the echoing has to happen as soon as the user hit the keyboard, and not only when the application running in the terminal processes the input.
    • Field Detail

      • DEFAULT_TERMINAL_ATTRIBUTES

        private static final java.lang.String DEFAULT_TERMINAL_ATTRIBUTES
        See Also:
        Constant Field Values
      • masterOutput

        protected final java.io.OutputStream masterOutput
      • slaveInputPipe

        protected final java.io.OutputStream slaveInputPipe
      • slaveWriter

        protected final java.io.PrintWriter slaveWriter
      • slaveOutput

        protected final java.io.OutputStream slaveOutput
      • attributes

        protected final Attributes attributes
        Console data
      • size

        protected final Size size
    • Constructor Detail

      • LineDisciplineTerminal

        public LineDisciplineTerminal​(java.lang.String name,
                                      java.lang.String type,
                                      java.io.OutputStream masterOutput,
                                      java.nio.charset.Charset encoding)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • LineDisciplineTerminal

        public LineDisciplineTerminal​(java.lang.String name,
                                      java.lang.String type,
                                      java.io.OutputStream masterOutput,
                                      java.nio.charset.Charset encoding,
                                      Terminal.SignalHandler signalHandler)
                               throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • reader

        public NonBlockingReader reader()
        Description copied from interface: Terminal
        Retrieve the Reader for this terminal. This is the standard way to read input from this terminal. The reader is non blocking.
        Returns:
        The non blocking reader
      • writer

        public java.io.PrintWriter writer()
        Description copied from interface: Terminal
        Retrieve the Writer for this terminal. This is the standard way to write to this terminal.
        Returns:
        The writer
      • input

        public java.io.InputStream input()
        Description copied from interface: Terminal
        Retrieve the input stream for this terminal. In some rare cases, there may be a need to access the terminal input stream directly. In the usual cases, use the Terminal.reader() instead.
        Returns:
        The input stream
        See Also:
        Terminal.reader()
      • output

        public java.io.OutputStream output()
        Description copied from interface: Terminal
        Retrieve the output stream for this terminal. In some rare cases, there may be a need to access the terminal output stream directly. In the usual cases, use the Terminal.writer() instead.
        Returns:
        The output stream
        See Also:
        Terminal.writer()
      • getAttributes

        public Attributes getAttributes()
        Description copied from interface: Terminal
        Returns the terminal attributes. The returned object can be safely modified further used in a call to Terminal.setAttributes(Attributes).
        Returns:
        the terminal attributes.
      • setAttributes

        public void setAttributes​(Attributes attr)
        Description copied from interface: Terminal
        Set the terminal attributes. The terminal will perform a copy of the given attributes.
        Parameters:
        attr - the new attributes
      • getSize

        public Size getSize()
        Description copied from interface: Terminal
        Retrieve the size of the visible window
        Returns:
        the visible terminal size
        See Also:
        Terminal.getBufferSize()
      • setSize

        public void setSize​(Size sz)
      • processInputByte

        public void processInputByte​(int c)
                              throws java.io.IOException
        Master input processing. All data coming to the terminal should be provided using this method.
        Parameters:
        c - the input byte
        Throws:
        java.io.IOException - if anything wrong happens
      • processInputBytes

        public void processInputBytes​(byte[] input)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • processInputBytes

        public void processInputBytes​(byte[] input,
                                      int offset,
                                      int length)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • doProcessInputByte

        protected boolean doProcessInputByte​(int c)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • processOutputByte

        protected void processOutputByte​(int c)
                                  throws java.io.IOException
        Master output processing. All data going to the master should be provided by this method.
        Parameters:
        c - the output byte
        Throws:
        java.io.IOException - if anything wrong happens
      • processIOException

        protected void processIOException​(java.io.IOException ioException)
      • doClose

        protected void doClose()
                        throws java.io.IOException
        Overrides:
        doClose in class AbstractTerminal
        Throws:
        java.io.IOException