AutoCloseable
, Closeable
, InputProvider
, Scrollable
AbstractScreen
, TerminalScreen
, VirtualScreen
public interface Screen extends InputProvider, Scrollable, Closeable
refresh
to have the screen automatically apply the changes in the back-buffer to the real terminal. The
screen tracks what's visible through a front-buffer, but this is completely managed internally and cannot be expected
to know what the terminal looks like if it's being modified externally.
If you want to do more complicated drawing operations, please see the class DefaultScreenWriter
which has many
utility methods that works on Screens.
Modifier and Type | Interface | Description |
---|---|---|
static class |
Screen.RefreshType |
This enum represents the different ways a Screen can refresh the screen, moving the back-buffer data into the
front-buffer that is being displayed.
|
Modifier and Type | Field | Description |
---|---|---|
static TextCharacter |
DEFAULT_CHARACTER |
This is the character Screen implementations should use as a filler is there are areas not set to any particular
character.
|
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
Erases all the characters on the screen, effectively giving you a blank area.
|
void |
close() |
Same as calling
stopScreen() |
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 |
getBackCharacter(int column,
int row) |
Reads a character and its associated meta-data from the back-buffer and returns it encapsulated as a
ScreenCharacter.
|
TextCharacter |
getBackCharacter(TerminalPosition position) |
Reads a character and its associated meta-data from the back-buffer and returns it encapsulated as a
ScreenCharacter.
|
TerminalPosition |
getCursorPosition() |
A screen implementation typically keeps a location on the screen where the cursor will be placed after drawing
and refreshing the buffers, this method returns that location.
|
TextCharacter |
getFrontCharacter(int column,
int row) |
Reads a character and its associated meta-data from the front-buffer and returns it encapsulated as a
ScreenCharacter.
|
TextCharacter |
getFrontCharacter(TerminalPosition position) |
Reads a character and its associated meta-data from the front-buffer and returns it encapsulated as a
ScreenCharacter.
|
TabBehaviour |
getTabBehaviour() |
Gets the behaviour for what to do about tab characters.
|
TerminalSize |
getTerminalSize() |
Returns the size of the screen.
|
TextGraphics |
newTextGraphics() |
Creates a new TextGraphics objects that is targeting this Screen for writing to.
|
void |
refresh() |
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 |
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) |
Scroll a range of lines of this Screen according to given distance.
|
void |
setCharacter(int column,
int row,
TextCharacter screenCharacter) |
Sets a character in the back-buffer to a specified value with specified colors and modifiers.
|
void |
setCharacter(TerminalPosition position,
TextCharacter screenCharacter) |
Sets a character in the back-buffer to a specified value with specified colors and modifiers.
|
void |
setCursorPosition(TerminalPosition position) |
A screen implementation typically keeps a location on the screen where the cursor will be placed after drawing
and refreshing the buffers, this method controls that location.
|
void |
setTabBehaviour(TabBehaviour tabBehaviour) |
Sets the behaviour for what to do about tab characters.
|
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() . |
pollInput, readInput
static final TextCharacter DEFAULT_CHARACTER
void startScreen() throws IOException
stopScreen()
.IOException
- if there was an underlying IO error when exiting from private modevoid close() throws IOException
stopScreen()
close
in interface AutoCloseable
close
in interface Closeable
IOException
- if there was an underlying IO error when exiting from private modevoid stopScreen() throws IOException
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 modevoid clear()
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.
TerminalPosition getCursorPosition()
null
if the
cursor is not visiblevoid setCursorPosition(TerminalPosition position)
position
- TerminalPosition of the new position where the cursor should be placed after refresh(), or if
null
, hides the cursorTabBehaviour getTabBehaviour()
TabBehaviour
void setTabBehaviour(TabBehaviour tabBehaviour)
tabBehaviour
- Tab behaviour to use when converting a \t character to a spacesTabBehaviour
TerminalSize getTerminalSize()
void setCharacter(int column, int row, TextCharacter screenCharacter)
column
- Column of the character to modify (x coordinate)row
- Row of the character to modify (y coordinate)screenCharacter
- New data to put at the specified positionvoid setCharacter(TerminalPosition position, TextCharacter screenCharacter)
position
- Which position in the terminal to modifyscreenCharacter
- New data to put at the specified positionTextGraphics newTextGraphics()
refresh()
on the screen to see your changes.TextCharacter getFrontCharacter(int column, int row)
column
- Which column to get the character fromrow
- Which row to get the character fromScreenCharacter
representation of the character in the front-buffer at the specified locationTextCharacter getFrontCharacter(TerminalPosition position)
position
- What position to read the character fromScreenCharacter
representation of the character in the front-buffer at the specified locationTextCharacter getBackCharacter(int column, int row)
column
- Which column to get the character fromrow
- Which row to get the character fromScreenCharacter
representation of the character in the back-buffer at the specified locationTextCharacter getBackCharacter(TerminalPosition position)
position
- What position to read the character fromScreenCharacter
representation of the character in the back-buffer at the specified locationvoid refresh() throws IOException
IOException
- If there was an underlying I/O errorScreen.RefreshType
void refresh(Screen.RefreshType refreshType) throws IOException
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
TerminalSize doResizeIfNecessary()
void scrollLines(int firstLine, int lastLine, int distance)
scrollLines
in interface Scrollable
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.