- java.lang.Object
-
- com.googlecode.lanterna.terminal.AbstractTerminal
-
- All Implemented Interfaces:
InputProvider
,Terminal
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
DefaultVirtualTerminal
,StreamBasedTerminal
public abstract class AbstractTerminal extends java.lang.Object implements Terminal
Containing a some very fundamental functionality that should be common (and usable) to all terminal implementations. All the Terminal implementers within Lanterna extends from this class.
-
-
Field Summary
Fields Modifier and Type Field Description private TerminalSize
lastKnownSize
private java.util.List<TerminalResizeListener>
resizeListeners
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTerminal()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addResizeListener(TerminalResizeListener listener)
Adds aTerminalResizeListener
to be called when the terminal has changed size.TextGraphics
newTextGraphics()
Creates a new TextGraphics object that uses this Terminal directly when outputting.protected void
onResized(int columns, int rows)
Call this method when the terminal has been resized or the initial size of the terminal has been discovered.protected void
onResized(TerminalSize newSize)
Call this method when the terminal has been resized or the initial size of the terminal has been discovered.void
removeResizeListener(TerminalResizeListener listener)
Removes aTerminalResizeListener
from the list of listeners to be notified when the terminal has changed size-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.googlecode.lanterna.input.InputProvider
pollInput, readInput
-
Methods inherited from interface com.googlecode.lanterna.terminal.Terminal
bell, clearScreen, close, disableSGR, enableSGR, enquireTerminal, enterPrivateMode, exitPrivateMode, flush, getCursorPosition, getTerminalSize, putCharacter, putString, resetColorAndSGR, setBackgroundColor, setCursorPosition, setCursorPosition, setCursorVisible, setForegroundColor
-
-
-
-
Field Detail
-
resizeListeners
private final java.util.List<TerminalResizeListener> resizeListeners
-
lastKnownSize
private TerminalSize lastKnownSize
-
-
Method Detail
-
addResizeListener
public void addResizeListener(TerminalResizeListener listener)
Description copied from interface:Terminal
Adds aTerminalResizeListener
to be called when the terminal has changed size. There is no guarantee that this listener will really be invoked when the terminal has changed size, at all depends on the terminal emulator implementation. Normally on Unix systems the WINCH signal will be sent to the process and lanterna can intercept this.There are no guarantees on what thread the call will be made on, so please be careful with what kind of operation you perform in this callback. You should probably not take too long to return.
- Specified by:
addResizeListener
in interfaceTerminal
- Parameters:
listener
- Listener object to be called when the terminal has been changed- See Also:
TerminalResizeListener
-
removeResizeListener
public void removeResizeListener(TerminalResizeListener listener)
Description copied from interface:Terminal
Removes aTerminalResizeListener
from the list of listeners to be notified when the terminal has changed size- Specified by:
removeResizeListener
in interfaceTerminal
- Parameters:
listener
- Listener object to remove- See Also:
TerminalResizeListener
-
onResized
protected void onResized(int columns, int rows)
Call this method when the terminal has been resized or the initial size of the terminal has been discovered. It will trigger all resize listeners, but only if the size has changed from before.- Parameters:
columns
- Number of columns in the new sizerows
- Number of rows in the new size
-
onResized
protected void onResized(TerminalSize newSize)
Call this method when the terminal has been resized or the initial size of the terminal has been discovered. It will trigger all resize listeners, but only if the size has changed from before.- Parameters:
newSize
- Last discovered terminal size
-
newTextGraphics
public TextGraphics newTextGraphics() throws java.io.IOException
Description copied from interface:Terminal
Creates a new TextGraphics object that uses this Terminal directly when outputting. Keep in mind that you are probably better off to switch to a Screen to make advanced text graphics more efficient. Also, this TextGraphics implementation will not call.flush()
after any operation, so you'll need to do that on your own.- Specified by:
newTextGraphics
in interfaceTerminal
- Returns:
- TextGraphics implementation that draws directly using this Terminal interface
- Throws:
java.io.IOException
- If there was an I/O error when setting up theTextGraphics
object
-
-