Scrollable
, InputProvider
, Screen
, Closeable
, AutoCloseable
public class TerminalScreen extends AbstractScreen
Screen.RefreshType
DEFAULT_CHARACTER
Constructor | Description |
---|---|
TerminalScreen(Terminal terminal) |
Creates a new Screen on top of a supplied terminal, will query the terminal for its size.
|
TerminalScreen(Terminal terminal,
TextCharacter defaultCharacter) |
Creates a new Screen on top of a supplied terminal, will query the terminal for its size.
|
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
Erases all the characters on the screen, effectively giving you a blank area.
|
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).
|
Terminal |
getTerminal() |
Returns the underlying
Terminal interface that this Screen is using. |
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) |
Perform the scrolling and save scroll-range and distance in order
to be able to optimize Terminal-update later.
|
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() . |
void |
stopScreen(boolean flushInput) |
addResizeRequest, close, getBackBuffer, getBackCharacter, getBackCharacter, getCursorPosition, getFrontBuffer, getFrontCharacter, getFrontCharacter, getTabBehaviour, getTerminalSize, newTextGraphics, refresh, setCharacter, setCharacter, setCursorPosition, setTabBehaviour, toString
public TerminalScreen(Terminal terminal) throws IOException
Before you can display the content of this buffered screen to the real underlying terminal, you must call the
startScreen()
method. This will ask the terminal to enter private mode (which is required for Screens to
work properly). Similarly, when you are done, you should call stopScreen()
which will exit private mode.
terminal
- Terminal object to create the DefaultScreen on top ofIOException
- If there was an underlying I/O error when querying the size of the terminalpublic TerminalScreen(Terminal terminal, TextCharacter defaultCharacter) throws IOException
Before you can display the content of this buffered screen to the real underlying terminal, you must call the
startScreen()
method. This will ask the terminal to enter private mode (which is required for Screens to
work properly). Similarly, when you are done, you should call stopScreen()
which will exit private mode.
terminal
- Terminal object to create the DefaultScreen on top of.defaultCharacter
- What character to use for the initial state of the screen and expanded areasIOException
- If there was an underlying I/O error when querying the size of the terminalpublic 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 void stopScreen(boolean flushInput) throws IOException
IOException
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 Terminal getTerminal()
Terminal
interface that this Screen is using.
Be aware: directly modifying the underlying terminal will most likely result in unexpected behaviour if
you then go on and try to interact with the Screen. The Screen's back-buffer/front-buffer will not know about
the operations you are going on the Terminal and won't be able to properly generate a refresh unless you enforce
a Screen.RefreshType.COMPLETE
, at which the entire terminal area will be repainted according to the
back-buffer of the Screen
.
public 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 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 void clear()
Screen
fill(TerminalPosition.TOP_LEFT_CORNER, getSize(), TextColor.ANSI.Default).
Please note that calling this method will only affect the back buffer, you need to call refresh to make the change visible.
clear
in interface Screen
clear
in class AbstractScreen
public TerminalSize doResizeIfNecessary()
Screen
doResizeIfNecessary
in interface Screen
doResizeIfNecessary
in class AbstractScreen
public void scrollLines(int firstLine, int lastLine, int distance)
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.