Scrollable
, InputProvider
, Screen
, Closeable
, AutoCloseable
public class VirtualScreen extends AbstractScreen
The use case for this class is to allow you to set a minimum size that you can count on be honored, no matter how small the user makes the terminal. This should make programming GUIs easier.
Modifier and Type | Class | Description |
---|---|---|
static interface |
VirtualScreen.FrameRenderer |
Interface for rendering the virtual screen's frame when the real terminal is too small for the virtual screen
|
Screen.RefreshType
DEFAULT_CHARACTER
Constructor | Description |
---|---|
VirtualScreen(Screen screen) |
Creates a new VirtualScreen that wraps a supplied Screen.
|
Modifier and Type | Method | Description |
---|---|---|
TerminalSize |
doResizeIfNecessary() |
One problem working with Screens is that whenever the terminal is resized, the front and back buffers needs to be
adjusted accordingly and the program should have a chance to figure out what to do with this extra space (or less
space).
|
TextCharacter |
getFrontCharacter(TerminalPosition position) |
Reads a character and its associated meta-data from the front-buffer and returns it encapsulated as a
ScreenCharacter.
|
TerminalSize |
getMinimumSize() |
Returns the minimum size this virtual screen can have.
|
TerminalSize |
getViewportSize() |
Returns the current size of the viewport.
|
KeyStroke |
pollInput() |
Returns the next
Key off the input queue or null if there is no more input events available. |
KeyStroke |
readInput() |
Returns the next
Key off the input queue or blocks until one is available. |
void |
refresh(Screen.RefreshType refreshType) |
This method will take the content from the back-buffer and move it into the front-buffer, making the changes
visible to the terminal in the process.
|
void |
scrollLines(int firstLine,
int lastLine,
int distance) |
Performs the scrolling on its back-buffer.
|
void |
setCursorPosition(TerminalPosition position) |
Moves the current cursor position or hides it.
|
void |
setMinimumSize(TerminalSize minimumSize) |
Sets the minimum size we want the virtual screen to have.
|
void |
setViewportTopLeft(TerminalPosition position) |
|
void |
startScreen() |
Before you can use a Screen, you need to start it.
|
void |
stopScreen() |
Calling this method will make the underlying terminal leave private mode, effectively going back to whatever
state the terminal was in before calling
startScreen() . |
addResizeRequest, clear, close, getBackBuffer, getBackCharacter, getBackCharacter, getCursorPosition, getFrontBuffer, getFrontCharacter, getTabBehaviour, getTerminalSize, newTextGraphics, refresh, setCharacter, setCharacter, setTabBehaviour, toString
public VirtualScreen(Screen screen)
Terminal
, it will have the correct size and content for what's
actually displayed to the user, but this class will present everything as one view with a fixed minimum size,
no matter what size the real terminal has.
The initial minimum size will be the current size of the screen.
screen
- Real screen that will be used when drawing the whole or partial virtual screenpublic void setMinimumSize(TerminalSize minimumSize)
minimumSize
- Minimum size we want the screen to havepublic TerminalSize getMinimumSize()
public TerminalSize getViewportSize()
VirtualScreen
public void setViewportTopLeft(TerminalPosition position)
public void startScreen() throws IOException
Screen
stopScreen()
.IOException
- if there was an underlying IO error when exiting from private modepublic void stopScreen() throws IOException
Screen
startScreen()
. Once a screen has been stopped, you can start it
again with startScreen()
which will restore the screens content to the terminal.IOException
- if there was an underlying IO error when exiting from private modepublic TextCharacter getFrontCharacter(TerminalPosition position)
Screen
getFrontCharacter
in interface Screen
getFrontCharacter
in class AbstractScreen
position
- What position to read the character fromScreenCharacter
representation of the character in the front-buffer at the specified locationpublic void setCursorPosition(TerminalPosition position)
AbstractScreen
setCursorPosition
in interface Screen
setCursorPosition
in class AbstractScreen
position
- 0-indexed column and row numbers of the new position, or if null
, hides the cursorpublic TerminalSize doResizeIfNecessary()
Screen
doResizeIfNecessary
in interface Screen
doResizeIfNecessary
in class AbstractScreen
public void refresh(Screen.RefreshType refreshType) throws IOException
Screen
Using this method call instead of refresh()
gives you a little bit more control over how the screen will
be refreshed.
refreshType
- What type of refresh to doIOException
- If there was an underlying I/O errorScreen.RefreshType
public KeyStroke pollInput() throws IOException
InputProvider
Key
off the input queue or null if there is no more input events available. Note, this
method call is not blocking, it returns null immediately if there is nothing on the input stream.IOException
- Propagated error if the underlying stream gave errorspublic KeyStroke readInput() throws IOException
InputProvider
Key
off the input queue or blocks until one is available. NOTE: In previous
versions of Lanterna, this method was not blocking. From lanterna 3, it is blocking and you can call
pollInput()
for the non-blocking version.IOException
- Propagated error if the underlying stream gave errorspublic void scrollLines(int firstLine, int lastLine, int distance)
AbstractScreen
scrollLines
in interface Screen
scrollLines
in interface Scrollable
scrollLines
in class AbstractScreen
firstLine
- first line of the range to be scrolled (top line is 0)lastLine
- last (inclusive) line of the range to be scrolleddistance
- if > 0: move lines up, else if < 0: move lines down.Copyright © 2020. All rights reserved.