Interface VirtualTerminal

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable, InputProvider, IOSafeTerminal, Terminal
    All Known Implementing Classes:
    DefaultVirtualTerminal

    public interface VirtualTerminal
    extends IOSafeTerminal
    A virtual terminal is a kind of terminal emulator implemented inside of Lanterna that exposes the Terminal interface and maintains its state completely internally. The VirtualTerminal interface extends this interface and allows you to query and modify its internals in a way you can not do with a regular terminal. The AWT and Swing terminal implementations in Lanterna uses the DefaultVirtualTerminal class internally for keeping its state and doing most of the terminal operations.
    • Method Detail

      • setTerminalSize

        void setTerminalSize​(TerminalSize newSize)
        Changes the "visible size" of the virtual terminal. This is the area at the bottom of the text buffer that is considered the workable area since the cursor is restricted to this space. If you call this method with a size that is different from the current size of the virtual terminal, the resize event will be fired on all listeners.
        Parameters:
        newSize - New size of the virtual terminal
      • addVirtualTerminalListener

        void addVirtualTerminalListener​(VirtualTerminalListener listener)
        Adds a listener to receive notifications when certain events happens on the virtual terminal. Notice that this is not the same as the list of TerminalResizeListener, but as the VirtualTerminalListener also allows you to listen on size changes, it can be used for the same purpose.
        Parameters:
        listener - Listener to receive events from this virtual terminal
      • removeVirtualTerminalListener

        void removeVirtualTerminalListener​(VirtualTerminalListener listener)
        Removes a listener from this virtual terminal so it will no longer receive events. Notice that this is not the same as the list of TerminalResizeListener.
        Parameters:
        listener - Listener to remove from this virtual terminal
      • setBacklogSize

        void setBacklogSize​(int backlogSize)
        Sets the number of rows to allow in the non-private buffer above the viewport. The total size of the text buffer will be backlogSize + terminalSize.getRows(). If set to 0, there is no scrollback. Please note that private mode is unaffected by this and will always have no backlog.
        Parameters:
        backlogSize - Number of rows of backlog
      • isCursorVisible

        boolean isCursorVisible()
        Checks if the terminal cursor is visible or not
        Returns:
        true if the terminal cursor is visible, false otherwise
      • getCursorBufferPosition

        TerminalPosition getCursorBufferPosition()
        Returns the position of the terminal cursor where the row index is counted from the top of the text buffer, including all backlog. This means, if there is 500 lines of backlog but the cursor position is set to 0x0, this method will return 0x500. If you want to get the cursor's position in the viewport, please use IOSafeTerminal.getCursorPosition() instead.
        Returns:
        Cursor position as an offset from the top-left position of the text buffer including any backlog
      • getBufferCharacter

        TextCharacter getBufferCharacter​(TerminalPosition position)
        Returns a character from this virtual terminal, relative to the top-left position of the text buffer including any backlog. If you want to get a character from the bottom viewport, please use getCharacter(TerminalPosition) instead.
        Parameters:
        position - Position to get the character from
        Returns:
        Text character at the specific position in the text buffer
      • getBufferCharacter

        TextCharacter getBufferCharacter​(int column,
                                         int row)
        Returns a character from this virtual terminal, relative to the top-left position of the text buffer including any backlog. If you want to get a character from the bottom viewport, please use getCharacter(int, int) instead.
        Parameters:
        column - Column to get the character from
        row - Row, counting from the first line in the backlog, to get the character from
        Returns:
        Text character at the specific position in the text buffer
      • getCharacter

        TextCharacter getCharacter​(TerminalPosition position)
        Returns a character from the viewport at the specified coordinates. This method cannot access the backlog, if you want to fetch a character potentially from the backlog, please use getBufferCharacter(TerminalPosition) instead.
        Parameters:
        position - Position of the character to return
        Returns:
        Text character at the specific position in the viewport
      • getCharacter

        TextCharacter getCharacter​(int column,
                                   int row)
        Returns a character from the viewport at the specified coordinates. This method cannot access the backlog, if you want to fetch a character potentially from the backlog, please use getBufferCharacter(int,int) instead.
        Parameters:
        column - Column in the viewport to get the character from
        row - Row in the viewport to get the character form
        Returns:
        Text character at the specific position in the viewport
      • getBufferLineCount

        int getBufferLineCount()
        Returns the number of lines in the entire text buffer, including any backlog
        Returns:
        Number of lines in the buffer
      • forEachLine

        void forEachLine​(int startRow,
                         int endRow,
                         VirtualTerminal.BufferWalker bufferWalker)
        Iterates over a range of lines in the text buffer
        Parameters:
        startRow - Index of the first row of the iteration, counting 0 as the first row in the backlog
        endRow - Index of the last row of the iteration (inclusive), counting 0 as the first row in the backlog
        bufferWalker - Callback to invoke on each row in the iteration