Package org.jline.builtins
Class ScreenTerminal
java.lang.Object
org.jline.builtins.ScreenTerminal
- All Implemented Interfaces:
Sized
- Direct Known Subclasses:
WebTerminal.WebTerminalComponent
A virtual terminal screen implementation.
This class provides a virtual terminal screen that can process ANSI escape sequences and maintain the state of a terminal display. It supports features including:
- Cursor positioning and movement
- Text attributes (bold, underline, etc.)
- Color support (including 256 colors)
- Screen clearing and scrolling
- Alternate screen buffer
- Screen resizing
This implementation is based on the Apache Karaf WebConsole Gogo plugin, with adaptations to support alternate screen, resizing, and 256 colors. It follows the ECMA-48 standard for terminal control sequences.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a ScreenTerminal using the default size of 80 columns and 24 rows.ScreenTerminal(int columns, int rows) Creates a ScreenTerminal with the specified number of columns and rows. -
Method Summary
Modifier and TypeMethodDescriptiondump()Dumps the terminal content as HTML with inline RGB color styles.voiddump(long[] fullscreen, int[] cursor) Dumps the raw screen content into a flat array.voiddump(long[] fullscreen, int ftop, int fleft, int fheight, int fwidth, int[] cursor) dump(long timeout, boolean forceDump) Dumps the terminal content as HTML with inline RGB color styles.booleandump(long timeout, boolean forceDump, long[] fullscreen, int[] cursor) Waits for the screen to be dirty, then dumps the raw screen content.booleandump(long timeout, boolean forceDump, long[] fullscreen, int ftop, int fleft, int fheight, int fwidth, int[] cursor) Waits for the screen to be dirty, then dumps the raw screen content into a subregion.intProvide the current number of columns in the terminal.intDeprecated.intgetRows()Gets the number of rows in the terminal.intgetWidth()Deprecated.UsegetColumns()instead.booleanisDirty()read()protected voidsetDirty()booleansetSize(int columns, int rows) Deprecated.UsesetSize(Sized)instead.booleanResize the terminal to the specified columns and rows.toString()voidbooleanwaitDirty(long timeout) Waits for the screen to become dirty, up to the given timeout.boolean
-
Field Details
-
MIN_SIZE
public static final int MIN_SIZE- See Also:
-
MAX_SIZE
public static final int MAX_SIZE- See Also:
-
-
Constructor Details
-
ScreenTerminal
public ScreenTerminal()Creates a ScreenTerminal using the default size of 80 columns and 24 rows. -
ScreenTerminal
public ScreenTerminal(int columns, int rows) Creates a ScreenTerminal with the specified number of columns and rows.- Parameters:
columns- the number of character columns for the terminalrows- the number of character rows for the terminal
-
-
Method Details
-
isDirty
public boolean isDirty() -
waitDirty
- Throws:
InterruptedException
-
waitDirty
Waits for the screen to become dirty, up to the given timeout. Uses a while loop to guard against spurious wakeups.- Parameters:
timeout- maximum time to wait in milliseconds; if<= 0, returns immediately- Returns:
- true if the screen is dirty
- Throws:
InterruptedException- if interrupted while waiting
-
setDirty
protected void setDirty() -
getColumns
public int getColumns()Provide the current number of columns in the terminal.- Specified by:
getColumnsin interfaceSized- Returns:
- the current number of columns
-
getRows
-
getWidth
Deprecated.UsegetColumns()instead.Gets the terminal width in characters.- Returns:
- the width in characters
-
getHeight
Deprecated.UsegetRows()instead.Gets the terminal height in characters.- Returns:
- the height in characters
-
setSize
Resize the terminal to the specified columns and rows.- Parameters:
sized- the new Size whose columns and rows will be applied- Returns:
- true if the size was set successfully, false otherwise
-
setSize
Deprecated.UsesetSize(Sized)instead.Resize the terminal to the given number of columns and rows.- Parameters:
columns- the target number of columns (2–256)rows- the target number of rows (2–256)- Returns:
- `true` if the size was changed; `false` if the requested dimensions are out of range
-
read
-
pipe
-
write
-
dump
public void dump(long[] fullscreen, int ftop, int fleft, int fheight, int fwidth, int[] cursor) -
dump
public void dump(long[] fullscreen, int[] cursor) Dumps the raw screen content into a flat array. The array must be at leastcolumns * rowselements long.- Parameters:
fullscreen- destination arraycursor- 2-element array to receive cursor [x, y], or null
-
dump
public boolean dump(long timeout, boolean forceDump, long[] fullscreen, int ftop, int fleft, int fheight, int fwidth, int[] cursor) throws InterruptedException Waits for the screen to be dirty, then dumps the raw screen content into a subregion.- Parameters:
timeout- maximum time to wait in millisecondsforceDump- if true, dump even if the screen is not dirtyfullscreen- destination array (must be at least fwidth * fheight)ftop- top row offsetfleft- left column offsetfheight- number of rows to dumpfwidth- number of columns to dumpcursor- 2-element array to receive cursor [x, y], or null- Returns:
- true if the screen was dumped
- Throws:
InterruptedException- if interrupted
-
dump
public boolean dump(long timeout, boolean forceDump, long[] fullscreen, int[] cursor) throws InterruptedException Waits for the screen to be dirty, then dumps the raw screen content.- Parameters:
timeout- maximum time to wait in millisecondsforceDump- if true, dump even if the screen is not dirtyfullscreen- destination array (must be at least columns * rows)cursor- 2-element array to receive cursor [x, y], or null- Returns:
- true if the screen was dumped
- Throws:
InterruptedException- if interrupted
-
dump
Dumps the terminal content as HTML with inline RGB color styles.- Parameters:
timeout- maximum time to wait for changes in millisecondsforceDump- whether to force a dump even if screen is not dirty- Returns:
- the terminal content as HTML, or null if no update
- Throws:
InterruptedException- if interrupted
-
dump
Dumps the terminal content as HTML with inline RGB color styles.- Returns:
- the terminal content as HTML.
-
toString
-
getRows()instead.