Class AbstractScreen
java.lang.Object
com.googlecode.lanterna.screen.AbstractScreen
- All Implemented Interfaces:
Scrollable, InputProvider, Screen, Closeable, AutoCloseable
- Direct Known Subclasses:
TerminalScreen, VirtualScreen
This class implements some of the Screen logic that is not directly tied to the actual implementation of how the
Screen translate to the terminal. It keeps data structures for the front- and back buffers, the cursor location and
some other simpler states.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Screen
Screen.RefreshType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ScreenBufferprivate TerminalPositionprivate final TextCharacterprivate ScreenBufferprivate TerminalSizeprivate TabBehaviourprivate TerminalSizeFields inherited from interface Screen
DEFAULT_CHARACTER -
Constructor Summary
ConstructorsConstructorDescriptionAbstractScreen(TerminalSize initialSize) AbstractScreen(TerminalSize initialSize, TextCharacter defaultCharacter) Creates a new Screen on top of a supplied terminal, will query the terminal for its size. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddResizeRequest(TerminalSize newSize) Tells this screen that the size has changed and it should, at next opportunity, resize itself and its buffersvoidclear()Erases all the characters on the screen, effectively giving you a blank area.voidclose()Same as callingScreen.stopScreen()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).private TerminalSizeprotected ScreenBufferReturns the back buffer connected to this screen, don't use this unless you know what you are doing!getBackCharacter(int column, int row) Reads a character and its associated meta-data from the back-buffer and returns it encapsulated as a ScreenCharacter.getBackCharacter(TerminalPosition position) Reads a character and its associated meta-data from the back-buffer and returns it encapsulated as a ScreenCharacter.private TextCharactergetCharacterFromBuffer(ScreenBuffer buffer, int column, int row) 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 ScreenBufferReturns the front buffer connected to this screen, don't use this unless you know what you are doing!getFrontCharacter(int column, int row) Reads a character and its associated meta-data from the front-buffer and returns it encapsulated as a ScreenCharacter.getFrontCharacter(TerminalPosition position) Reads a character and its associated meta-data from the front-buffer and returns it encapsulated as a ScreenCharacter.Gets the behaviour for what to do about tab characters.Returns the size of the screen.Creates a new TextGraphics objects that is targeting this Screen for writing to.voidrefresh()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.voidscrollLines(int firstLine, int lastLine, int distance) Performs the scrolling on its back-buffer.voidsetCharacter(int column, int row, TextCharacter screenCharacter) Sets a character in the back-buffer to a specified value with specified colors and modifiers.voidsetCharacter(TerminalPosition position, TextCharacter screenCharacter) Sets a character in the back-buffer to a specified value with specified colors and modifiers.voidsetCursorPosition(TerminalPosition position) Moves the current cursor position or hides it.voidsetTabBehaviour(TabBehaviour tabBehaviour) Sets the behaviour for what to do about tab characters.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface InputProvider
pollInput, readInputMethods inherited from interface Screen
refresh, startScreen, stopScreen
-
Field Details
-
cursorPosition
-
backBuffer
-
frontBuffer
-
defaultCharacter
-
tabBehaviour
-
terminalSize
-
latestResizeRequest
-
-
Constructor Details
-
AbstractScreen
-
AbstractScreen
Creates a new Screen on top of a supplied terminal, will query the terminal for its size. The screen is initially blank. You can specify which character you wish to be used to fill the screen initially; this will also be the character used if the terminal is enlarged and you don't set anything on the new areas.- Parameters:
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 areas
-
-
Method Details
-
getCursorPosition
Description copied from interface:ScreenA 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. If it returns null, it means that the terminal will attempt to hide the cursor (if supported by the terminal).- Specified by:
getCursorPositionin interfaceScreen- Returns:
- Position where the cursor will be located after the screen has been refreshed or
nullif the cursor is not visible
-
setCursorPosition
Moves the current cursor position or hides it. If the cursor is hidden and given a new position, it will be visible after this method call.- Specified by:
setCursorPositionin interfaceScreen- Parameters:
position- 0-indexed column and row numbers of the new position, or ifnull, hides the cursor
-
setTabBehaviour
Description copied from interface:ScreenSets the behaviour for what to do about tab characters. If a tab character is written to the Screen, it would cause issues because we don't know how the terminal emulator would render it and we wouldn't know what state the front-buffer is in. Because of this, we convert tabs to a determined number of spaces depending on different rules that are available.- Specified by:
setTabBehaviourin interfaceScreen- Parameters:
tabBehaviour- Tab behaviour to use when converting a \t character to a spaces- See Also:
-
getTabBehaviour
Description copied from interface:ScreenGets the behaviour for what to do about tab characters. If a tab character is written to the Screen, it would cause issues because we don't know how the terminal emulator would render it and we wouldn't know what state the front-buffer is in. Because of this, we convert tabs to a determined number of spaces depending on different rules that are available.- Specified by:
getTabBehaviourin interfaceScreen- Returns:
- Tab behaviour that is used currently
- See Also:
-
setCharacter
Description copied from interface:ScreenSets a character in the back-buffer to a specified value with specified colors and modifiers.- Specified by:
setCharacterin interfaceScreen- Parameters:
position- Which position in the terminal to modifyscreenCharacter- New data to put at the specified position
-
newTextGraphics
Description copied from interface:ScreenCreates a new TextGraphics objects that is targeting this Screen for writing to. Any operations done on this TextGraphics will be affecting this screen. Remember to callrefresh()on the screen to see your changes.- Specified by:
newTextGraphicsin interfaceScreen- Returns:
- New TextGraphic object targeting this Screen
-
setCharacter
Description copied from interface:ScreenSets a character in the back-buffer to a specified value with specified colors and modifiers.- Specified by:
setCharacterin interfaceScreen- Parameters:
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 position
-
getFrontCharacter
Description copied from interface:ScreenReads a character and its associated meta-data from the front-buffer and returns it encapsulated as a ScreenCharacter.- Specified by:
getFrontCharacterin interfaceScreen- Parameters:
position- What position to read the character from- Returns:
- A
ScreenCharacterrepresentation of the character in the front-buffer at the specified location
-
getFrontCharacter
Description copied from interface:ScreenReads a character and its associated meta-data from the front-buffer and returns it encapsulated as a ScreenCharacter.- Specified by:
getFrontCharacterin interfaceScreen- Parameters:
column- Which column to get the character fromrow- Which row to get the character from- Returns:
- A
ScreenCharacterrepresentation of the character in the front-buffer at the specified location
-
getBackCharacter
Description copied from interface:ScreenReads a character and its associated meta-data from the back-buffer and returns it encapsulated as a ScreenCharacter.- Specified by:
getBackCharacterin interfaceScreen- Parameters:
position- What position to read the character from- Returns:
- A
ScreenCharacterrepresentation of the character in the back-buffer at the specified location
-
getBackCharacter
Description copied from interface:ScreenReads a character and its associated meta-data from the back-buffer and returns it encapsulated as a ScreenCharacter.- Specified by:
getBackCharacterin interfaceScreen- Parameters:
column- Which column to get the character fromrow- Which row to get the character from- Returns:
- A
ScreenCharacterrepresentation of the character in the back-buffer at the specified location
-
refresh
Description copied from interface:ScreenThis 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. The graphics workflow with Screen would involve drawing text and text-like graphics on the back buffer and then finally calling refresh(..) to make it visible to the user.- Specified by:
refreshin interfaceScreen- Throws:
IOException- If there was an underlying I/O error- See Also:
-
close
Description copied from interface:ScreenSame as callingScreen.stopScreen()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceScreen- Throws:
IOException- if there was an underlying IO error when exiting from private mode
-
clear
public void clear()Description copied from interface:ScreenErases all the characters on the screen, effectively giving you a blank area. The default background color will be used. This is effectively the same as callingfill(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.
-
doResizeIfNecessary
Description copied from interface:ScreenOne 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). The solution is to call, at the start of your rendering code, this method, which will check if the terminal has been resized and in that case update the internals of the Screen. After this call finishes, the screen's internal buffers will match the most recent size report from the underlying terminal.- Specified by:
doResizeIfNecessaryin interfaceScreen- Returns:
- If the terminal has been resized since this method was last called, it will return the new size of the terminal. If not, it will return null.
-
getTerminalSize
Description copied from interface:ScreenReturns the size of the screen. This call is not blocking but should return the size of the screen as it is represented by the buffer at the time this method is called.- Specified by:
getTerminalSizein interfaceScreen- Returns:
- Size of the screen, in columns and rows
-
getFrontBuffer
Returns the front buffer connected to this screen, don't use this unless you know what you are doing!- Returns:
- This Screen's front buffer
-
getBackBuffer
Returns the back buffer connected to this screen, don't use this unless you know what you are doing!- Returns:
- This Screen's back buffer
-
getAndClearPendingResize
-
addResizeRequest
Tells this screen that the size has changed and it should, at next opportunity, resize itself and its buffers- Parameters:
newSize- New size the 'real' terminal now has
-
getCharacterFromBuffer
-
toString
-
scrollLines
public void scrollLines(int firstLine, int lastLine, int distance) Performs the scrolling on its back-buffer.- Specified by:
scrollLinesin interfaceScreen- Specified by:
scrollLinesin interfaceScrollable- Parameters:
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.
-