Module com.googlecode.lanterna
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. TheVirtualTerminal
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 theDefaultVirtualTerminal
class internally for keeping its state and doing most of the terminal operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
VirtualTerminal.BufferLine
Interface used byVirtualTerminal.BufferWalker
to repressent a line in the text buffer when iterating over a range of linesstatic interface
VirtualTerminal.BufferWalker
Callback interface that is used byforEachLine(int, int, BufferWalker)
as a way to iterate over a range of lines in the text buffer
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addInput(KeyStroke keyStroke)
Adds aKeyStroke
to the input queue of this virtual terminal.void
addVirtualTerminalListener(VirtualTerminalListener listener)
Adds a listener to receive notifications when certain events happens on the virtual terminal.void
forEachLine(int startRow, int endRow, VirtualTerminal.BufferWalker bufferWalker)
Iterates over a range of lines in the text bufferTextCharacter
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.TextCharacter
getBufferCharacter(TerminalPosition position)
Returns a character from this virtual terminal, relative to the top-left position of the text buffer including any backlog.int
getBufferLineCount()
Returns the number of lines in the entire text buffer, including any backlogTextCharacter
getCharacter(int column, int row)
Returns a character from the viewport at the specified coordinates.TextCharacter
getCharacter(TerminalPosition position)
Returns a character from the viewport at the specified coordinates.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.boolean
isCursorVisible()
Checks if the terminal cursor is visible or notvoid
removeVirtualTerminalListener(VirtualTerminalListener listener)
Removes a listener from this virtual terminal so it will no longer receive events.void
setBacklogSize(int backlogSize)
Sets the number of rows to allow in the non-private buffer above the viewport.void
setTerminalSize(TerminalSize newSize)
Changes the "visible size" of the virtual terminal.-
Methods inherited from interface com.googlecode.lanterna.terminal.IOSafeTerminal
bell, clearScreen, close, disableSGR, enableSGR, enquireTerminal, enterPrivateMode, exitPrivateMode, flush, getCursorPosition, getTerminalSize, pollInput, putCharacter, putString, readInput, resetColorAndSGR, setBackgroundColor, setCursorPosition, setCursorPosition, setCursorVisible, setForegroundColor
-
Methods inherited from interface com.googlecode.lanterna.terminal.Terminal
addResizeListener, newTextGraphics, removeResizeListener
-
-
-
-
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 ofTerminalResizeListener
, but as theVirtualTerminalListener
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 ofTerminalResizeListener
.- 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 bebacklogSize + 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
-
addInput
void addInput(KeyStroke keyStroke)
Adds aKeyStroke
to the input queue of this virtual terminal. This even will be read the next time eitherIOSafeTerminal.pollInput()
orIOSafeTerminal.readInput()
is called, assuming there are no other events before it in the queue.- Parameters:
keyStroke
-KeyStroke
to add to the input queue of this virtual terminal
-
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 useIOSafeTerminal.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 usegetCharacter(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 usegetCharacter(int, int)
instead.- Parameters:
column
- Column to get the character fromrow
- 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 usegetBufferCharacter(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 usegetBufferCharacter(int,int)
instead.- Parameters:
column
- Column in the viewport to get the character fromrow
- 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 backlogendRow
- Index of the last row of the iteration (inclusive), counting 0 as the first row in the backlogbufferWalker
- Callback to invoke on each row in the iteration
-
-