Scrollable
, InputProvider
, Screen
, Closeable
, AutoCloseable
TerminalScreen
, VirtualScreen
public abstract class AbstractScreen extends Object implements Screen
Screen.RefreshType
DEFAULT_CHARACTER
Constructor | Description |
---|---|
AbstractScreen(TerminalSize initialSize) |
|
AbstractScreen(TerminalSize initialSize,
TextCharacter defaultCharacter) |
Creates a new Screen on top of a supplied terminal, will query the terminal for its size.
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
addResizeRequest(TerminalSize newSize) |
Tells this screen that the size has changed and it should, at next opportunity, resize itself and its buffers
|
void |
clear() |
Erases all the characters on the screen, effectively giving you a blank area.
|
void |
close() |
Same as calling
Screen.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).
|
protected ScreenBuffer |
getBackBuffer() |
Returns the back buffer connected to this screen, don't use this unless you know what you are doing!
|
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.
|
protected ScreenBuffer |
getFrontBuffer() |
Returns the front buffer connected to this screen, don't use this unless you know what you are doing!
|
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 |
scrollLines(int firstLine,
int lastLine,
int distance) |
Performs the scrolling on its back-buffer.
|
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) |
Moves the current cursor position or hides it.
|
void |
setTabBehaviour(TabBehaviour tabBehaviour) |
Sets the behaviour for what to do about tab characters.
|
String |
toString() |
pollInput, readInput
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
refresh, startScreen, stopScreen
public AbstractScreen(TerminalSize initialSize)
public AbstractScreen(TerminalSize initialSize, TextCharacter defaultCharacter)
initialSize
- Size to initially create the Screen with (can be resized later)defaultCharacter
- What character to use for the initial state of the screen and expanded areaspublic TerminalPosition getCursorPosition()
Screen
getCursorPosition
in interface Screen
null
if the
cursor is not visiblepublic void setCursorPosition(TerminalPosition position)
setCursorPosition
in interface Screen
position
- 0-indexed column and row numbers of the new position, or if null
, hides the cursorpublic void setTabBehaviour(TabBehaviour tabBehaviour)
Screen
setTabBehaviour
in interface Screen
tabBehaviour
- Tab behaviour to use when converting a \t character to a spacesTabBehaviour
public TabBehaviour getTabBehaviour()
Screen
getTabBehaviour
in interface Screen
TabBehaviour
public void setCharacter(TerminalPosition position, TextCharacter screenCharacter)
Screen
setCharacter
in interface Screen
position
- Which position in the terminal to modifyscreenCharacter
- New data to put at the specified positionpublic TextGraphics newTextGraphics()
Screen
refresh()
on the screen to see your changes.newTextGraphics
in interface Screen
public void setCharacter(int column, int row, TextCharacter screenCharacter)
Screen
setCharacter
in interface Screen
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 positionpublic TextCharacter getFrontCharacter(TerminalPosition position)
Screen
getFrontCharacter
in interface Screen
position
- What position to read the character fromScreenCharacter
representation of the character in the front-buffer at the specified locationpublic TextCharacter getFrontCharacter(int column, int row)
Screen
getFrontCharacter
in interface Screen
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 locationpublic TextCharacter getBackCharacter(TerminalPosition position)
Screen
getBackCharacter
in interface Screen
position
- What position to read the character fromScreenCharacter
representation of the character in the back-buffer at the specified locationpublic TextCharacter getBackCharacter(int column, int row)
Screen
getBackCharacter
in interface Screen
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 locationpublic void refresh() throws IOException
Screen
refresh
in interface Screen
IOException
- If there was an underlying I/O errorScreen.RefreshType
public void close() throws IOException
Screen
Screen.stopScreen()
close
in interface AutoCloseable
close
in interface Closeable
close
in interface Screen
IOException
- if there was an underlying IO error when exiting from private modepublic 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.
public TerminalSize doResizeIfNecessary()
Screen
doResizeIfNecessary
in interface Screen
public TerminalSize getTerminalSize()
Screen
getTerminalSize
in interface Screen
protected ScreenBuffer getFrontBuffer()
protected ScreenBuffer getBackBuffer()
protected void addResizeRequest(TerminalSize newSize)
newSize
- New size the 'real' terminal now haspublic void scrollLines(int firstLine, int lastLine, int distance)
scrollLines
in interface Screen
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.