Module com.googlecode.lanterna
Package com.googlecode.lanterna.terminal
Class SimpleTerminalResizeListener
- java.lang.Object
-
- com.googlecode.lanterna.terminal.SimpleTerminalResizeListener
-
- All Implemented Interfaces:
TerminalResizeListener
public class SimpleTerminalResizeListener extends java.lang.Object implements TerminalResizeListener
This class is a simple implementation of Terminal.ResizeListener which will keep track of the size of the terminal and let you know if the terminal has been resized since you last checked. This can be useful to avoid threading problems with the resize callback when your application is using a main event loop.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) TerminalSize
lastKnownSize
(package private) boolean
wasResized
-
Constructor Summary
Constructors Constructor Description SimpleTerminalResizeListener(TerminalSize initialSize)
Creates a new SimpleTerminalResizeListener
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TerminalSize
getLastKnownSize()
Returns the last known size the Terminal is supposed to have.boolean
isTerminalResized()
Checks if the terminal was resized since the last time this method was called.void
onResized(Terminal terminal, TerminalSize newSize)
The terminal has changed its size, most likely because the user has resized the window.
-
-
-
Field Detail
-
wasResized
boolean wasResized
-
lastKnownSize
TerminalSize lastKnownSize
-
-
Constructor Detail
-
SimpleTerminalResizeListener
public SimpleTerminalResizeListener(TerminalSize initialSize)
Creates a new SimpleTerminalResizeListener- Parameters:
initialSize
- Before any resize event, this listener doesn't know the size of the terminal. By supplying a value here, you control what getLastKnownSize() will return if invoked before any resize events has reached us.
-
-
Method Detail
-
isTerminalResized
public boolean isTerminalResized()
Checks if the terminal was resized since the last time this method was called. If this is the first time calling this method, the result is going to be based on if the terminal has been resized since this listener was attached to the Terminal.- Returns:
- true if the terminal was resized, false otherwise
-
getLastKnownSize
public TerminalSize getLastKnownSize()
Returns the last known size the Terminal is supposed to have.- Returns:
- Size of the terminal, as of the last resize update
-
onResized
public void onResized(Terminal terminal, TerminalSize newSize)
Description copied from interface:TerminalResizeListener
The terminal has changed its size, most likely because the user has resized the window. This callback is invoked by something inside the lanterna library, it could be a signal handler thread, it could be the AWT thread, it could be something else, so please be careful with what kind of operation you do in here. Also, make sure not to take too long before returning. Best practice would be to update an internal status in your program to mark that the terminal has been resized (possibly along with the new size) and then in your main loop you deal with this at the beginning of each redraw.- Specified by:
onResized
in interfaceTerminalResizeListener
- Parameters:
terminal
- Terminal that was resizednewSize
- Size of the terminal after the resize
-
-