public class RedirectedTerminal extends BasePrimitives
The virtual terminal is the internal buffers/state of this class and the physical terminal is the output stream.
Progress' semantics of streams require an instance of this class for every stream.
The output to the redirected terminal remains buffered for as long as the target frame remains unchanged. For this reason, the terminal maintains the ID of the last used frame and flushes the buffered output, if any, the same moment the ID change is detected.
Modifier and Type | Field and Description |
---|---|
private ScreenBitmap |
bitmap
The screen state, which keeps track of all the clipped regions.
|
private boolean[] |
box
The whether a box was requested for each corresponding line.
|
private java.util.Set<java.lang.Integer> |
breakable
Set of line numbers where page breaks may occur
|
private char[][] |
buffer
The 2-dimensional array of characters which is the virtual terminal.
|
private int |
cols
Number of columns on the screen.
|
private CoordinatesConversion |
conversion
The coordinates conversion implementation.
|
private int |
cx
The current X coordinate of the cursor.
|
private int |
cy
The current Y coordinate of the cursor.
|
private int |
first
The first line of valid output.
|
private int |
headerLines
Number of header lines in this frame
|
private java.lang.String |
headers
Accumulated headers
|
private boolean |
inHeaders
breakable output is in headers processing
|
private int |
last
The last line of valid output.
|
private int |
lastId
The frame ID of the frame currently owning the buffer
|
private int |
lines
Number of lines on the screen.
|
private int[] |
num
The number of valid characters in each corresponding line.
|
private Stream |
out
The output destination.
|
private boolean |
reset
true if the last operation was flushing to the stream. |
private boolean |
syncable
Terminal is syncable flag
|
private int |
width
Current logical width of terminal.
|
cursorInvalid, EMPTY_CELL
Constructor and Description |
---|
RedirectedTerminal(Stream out,
int cols,
int lines)
Initializes an instance for a specific output destination.
|
Modifier and Type | Method and Description |
---|---|
private void |
addChar(char chr,
Color color)
Add a character to the virtual terminal at the current cursor position.
|
void |
append(int chr,
Color color)
Add a character to the virtual terminal at the current cursor position.
|
void |
append(java.lang.String str,
Color color)
Add a string to the virtual terminal at the current cursor position.
|
void |
box(int left,
int top,
int right,
int bottom,
Color color)
Draw a box using the specified dimensions and color pair.
|
private void |
clear()
Wipe the slate clean (initialize our state to its pristine condition).
|
void |
clearArea(int left,
int top,
int right,
int bottom,
Color color)
Blank out a box using the specified attributes and color pair.
|
boolean |
cursorAt(int x,
int y)
Position the virtual cursor during the drawing.
|
boolean |
cursorStay(int x,
int y)
Position the real cursor.
|
void |
drawHBorder(int col,
int row,
int width,
Color color)
Draw the upper or lower border.
|
private void |
drawHorizontalLine(int length,
char ch,
Color color)
Draw a horizontal line of the specified length starting at the current
cursor position.
|
void |
drawLLCorner(int col,
int row,
Color color)
Draw the lower-left border corner.
|
void |
drawLRCorner(int col,
int row,
Color color)
Draw the lower-right border corner.
|
void |
drawULCorner(int col,
int row,
Color color)
Draw the upper-left border corner.
|
void |
drawURCorner(int col,
int row,
Color color)
Draw the upper-right border corner.
|
void |
drawVBorder(int col,
int row,
int height,
Color color)
Draw the left or right border.
|
private void |
firstOutput()
Any location in this class where content can be written to the buffer
must call this method to notify that this is the first output for a
fresh buffer.
|
boolean |
flush()
Attempts flushing of the buffered output.
|
ScreenBitmap |
getScreenBitmap()
Get the screen bitmap for this output primitives implementation.
|
int |
getX()
Get absolute X position of the cursor.
|
int |
getY()
Get absolute Y position of the cursor.
|
boolean |
hasBoxBorderCorners()
Check if this output primitives implementation requires border corners
when drawing a box.
|
void |
hLine(int length,
Color color)
Draw a horizontal line of the specified length starting at the current
cursor position.
|
boolean |
isFresh()
Checks the state of the terminal's buffer.
|
void |
markBreakLines(int first,
int height)
Notifies that the lines in the buffer belong to an editor and as such
can break the current page.
|
void |
markHeader(int height)
Notifies that the buffer image contains frame header and passes the
number of lines in the header.
|
void |
moveOutputToColumn(int fromCol,
int toCol)
Move the current output data to the new column.
|
boolean |
needsHeadersOutput()
Detects if headers need to be output.
|
void |
processHeaders()
Process headers if necessary.
|
void |
refresh(NativeRectangle rect)
Mark a rectangle as needing repainting.
|
void |
resetLastId(int id)
Reset last frame ID.
|
int |
screenHeight()
Gets the number of rows on the screen.
|
int |
screenWidth()
Gets the number of columns on the screen.
|
void |
setLogicalWidth(int width)
Set logical terminal width.
|
void |
setScreenBitmap(ScreenBitmap bitmap)
Replace the current bitmap instance with a previous one.
|
void |
setSyncable(boolean syncable)
Overrides the syncable flag.
|
void |
sync()
Synchronize the state of the physical terminal with the state of
the virtual terminal.
|
int |
targetFrame(int id)
Notifies the terminal about the target frame for the subsequent output.
|
java.lang.String[] |
view()
Debugging Aid.
|
void |
vLine(int length,
Color color)
Draw a vertical line of the specified length starting at the current
cursor position.
|
borderColor, cellAt, getWindowId, isCursorInvalid, setCursorInvalid, updateScreen, widgetColor
private int width
private int cols
private int lines
private Stream out
private int cx
private int cy
private boolean reset
true
if the last operation was flushing to the stream.private int first
private int last
private int[] num
private boolean[] box
private char[][] buffer
private boolean syncable
private int lastId
private java.util.Set<java.lang.Integer> breakable
private int headerLines
private java.lang.String headers
private boolean inHeaders
private ScreenBitmap bitmap
private CoordinatesConversion conversion
public RedirectedTerminal(Stream out, int cols, int lines)
out
- The output destination. Must not be null
.cols
- The width of each line in characters.lines
- The number of lines in the "screen".public ScreenBitmap getScreenBitmap()
public void setScreenBitmap(ScreenBitmap bitmap)
bitmap
- The new bitmap instance.public void append(int chr, Color color)
append
in class BasePrimitives
chr
- The character to output.color
- The color to use.public void append(java.lang.String str, Color color)
append
in class BasePrimitives
str
- The text to output.color
- The color to use.public void hLine(int length, Color color)
hLine
in class BasePrimitives
length
- The length of the line to draw in columns.color
- The color to use.public void vLine(int length, Color color)
vLine
in class BasePrimitives
length
- The length of the line to draw in rows.color
- The color to use.public void clearArea(int left, int top, int right, int bottom, Color color)
left
- The left column of the rectangle.top
- The top row of the rectangle.right
- The right column of the rectangle.bottom
- The bottom row of the rectangle.color
- The color to use.public void drawULCorner(int col, int row, Color color)
drawULCorner
in class BasePrimitives
col
- The column number where to draw.row
- The row number where to draw.color
- The color to use.public void drawURCorner(int col, int row, Color color)
drawURCorner
in class BasePrimitives
col
- The column number where to draw.row
- The row number where to draw.color
- The color to use.public void drawLLCorner(int col, int row, Color color)
drawLLCorner
in class BasePrimitives
col
- The column number where to draw.row
- The row number where to draw.color
- The color to use.public void drawLRCorner(int col, int row, Color color)
drawLRCorner
in class BasePrimitives
col
- The column number where to draw.row
- The row number where to draw.color
- The color to use.public void drawHBorder(int col, int row, int width, Color color)
drawHBorder
in class BasePrimitives
col
- The column number where to draw.row
- The row number where to draw.width
- The border width.color
- The color to use.public void drawVBorder(int col, int row, int height, Color color)
drawVBorder
in class BasePrimitives
col
- The column number where to draw.row
- The row number where to draw.height
- The border height.color
- The color to use.public boolean hasBoxBorderCorners()
false
.hasBoxBorderCorners
in class BasePrimitives
false
, as the box should not be drawn with border
corners.public void box(int left, int top, int right, int bottom, Color color)
box
in class BasePrimitives
left
- The left column of the rectangle.top
- The top row of the rectangle.right
- The right column of the rectangle.bottom
- The bottom row of the rectangle.color
- The color to use.public int getX()
getX
in class BasePrimitives
public int getY()
getY
in class BasePrimitives
public boolean cursorAt(int x, int y)
cursorAt
in class BasePrimitives
x
- Cursor X coordinate.y
- Cursor Y coordinate.true
if cursor positioning succeeded.public boolean cursorStay(int x, int y)
cursorStay
in class BasePrimitives
x
- Cursor X coordinate.y
- Cursor Y coordinate.true
if cursor positioning succeeded.public void refresh(NativeRectangle rect)
rect
- rectangle to mark for repaintingpublic boolean isFresh()
true
if the buffer is empty.public int targetFrame(int id)
id
- frame ID for the subsequent outputpublic void resetLastId(int id)
id
- The frame ID.public boolean flush()
true
if the buffer wasn't empty and has been
flushed.public void setSyncable(boolean syncable)
syncable
- new state of the flagpublic int screenWidth()
public int screenHeight()
public void sync()
During this synchronization the contents of the redirected terminal are flushed to the target stream and the terminal is cleared.
If the contents belong to a frame without editors, flushing to the stream is done in a single block that fits the current page. Otherwise, the syncing procedure watches the current page growing and inserts page break and, possibly, frame header if the output is at one of the breakable lines.
public java.lang.String[] view()
public void setLogicalWidth(int width)
width
- New terminal width.public void processHeaders()
public void markHeader(int height)
height
- public void markBreakLines(int first, int height)
first
- line number within the redirected terminal's buffer for the
first line of the rangeheight
- number of lines in this rangepublic boolean needsHeadersOutput()
true
if header processing is not in process and
the stream has registered page headers and the next line
number is 1 (we have no output on the current page).public void moveOutputToColumn(int fromCol, int toCol)
fromCol
- The original column where current output starts.toCol
- The column where to move the current output.private void addChar(char chr, Color color)
chr
- The character to output.color
- The color to use.private void firstOutput()
Stream.processHeaders()
to test if this
is the first output on a new page. If so, any page headers will be
output. Note that erasing output is not considered causing output on
the page. After this notification, the reset
flag will
be forced to false
.private void clear()
private void drawHorizontalLine(int length, char ch, Color color)
length
- The length of the line to draw in columns.ch
- The drawing character to use.color
- The color to use.