public class TerminalStream extends Stream
FileStream
), but processes pause as interactive terminal.
Terminal stream handles paging differently than regular stream. In particular, it has different default page size dictated by terminal height and each page triggers a pause which requires user action (pressing a key).
Modifier and Type | Class and Description |
---|---|
(package private) class |
TerminalStream.Syncronizer
This class handles saving buffer state and refreshing terminal as
necessary.
|
Stream.PrintMode
Modifier and Type | Field and Description |
---|---|
private char[] |
buffer
Screen buffer.
|
private int |
cols
Number of screen columns.
|
private int |
cursor
Cursor position.
|
private boolean |
outputStarted
Track start of the output is started.
|
private int |
rows
Number of screen rows.
|
private int |
start
Start of the buffer.
|
private ChuiOutputManager |
tk
Reference to toolkit.
|
private BasePrimitives |
worker
Reference to interactive output worker.
|
binary, convert, CR, DELIM, doneIn, doneOut, EOF, increment, LF, MODE_EXPORT, MODE_PUT_CONTROL, MODE_PUT_NORMAL, MODE_PUT_UNFORMATTED, NEWLINE, NEWLINE_LEN, PAGED_DEFAULT, PIPE_BROKEN_MESSAGE, SET_PAGED_DEFAULT, sourceCp, targetCp
Constructor and Description |
---|
TerminalStream()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
assign(Stream stream)
Assigns the internal stream reference to the given reference, in
actuality this has no effect.
|
long |
available()
The number of bytes available to be immediately read without blocking.
|
void |
close()
Closes the stream and releases OS resources associated with it, in
actuality this has no effect.
|
void |
closeIn()
Closes the input stream and releases OS resources associated with it,
in actuality this has no effect.
|
void |
closeOut()
Closes the output stream and clears the interactive terminal screen.
|
long |
getLen()
The length of the stream in bytes.
|
long |
getPos()
The 0-based offset into the stream at which the next read or write will
occur.
|
private void |
insertFormFeed()
Insert 4 empty lines.
|
boolean |
isIn()
State of the input side of the stream.
|
boolean |
isOut()
State of the output side of the stream.
|
int |
peekCh()
Peeks at the character from the current read position in the stream.
|
(package private) void |
rawSetPageSize(int sz)
Sets the current page size in lines.
|
int |
readCh()
Read a character from the current read position in the stream.
|
java.lang.String |
readLn()
Read all characters from the current read position in the stream to the
next line separator (as determined by the
File.separator
or to the EOF . |
private void |
refreshRow(int row)
Refresh content of specified row.
|
private void |
refreshScreen()
Refresh content of entire screen.
|
void |
setLen(long len)
Truncates or extends the stream to the specified length if this stream
supports such an operation, in actuality this has no effect.
|
void |
setPos(long pos)
Moves the current read/write position to the specified absolute 0-based
offset, in actuality this has no effect.
|
private void |
syncTeletype(char ch)
Simulate TTY output of single character and synchronize terminal when
processing is finished.
|
private void |
syncTeletypeString(java.lang.String data)
Simulate TTY output of string and synchronize terminal when processing
is finished.
|
private void |
teletype(char ch)
Simulate TTY output.
|
void |
write(byte[] data)
Write the given byte array to the output stream.
|
void |
write(byte[] data,
int off,
int len)
Write the specified range of bytes from the given byte array to the output stream.
|
void |
write(java.lang.String data)
Write the given string to the output stream.
|
void |
writeByte(byte b)
Write the given byte to the output stream.
|
void |
writeCh(char ch)
Write the given character to the output stream.
|
advancePage, afterWrite, assignDatum, cleanup, deleted, deregisterFooter, deregisterHeader, endOutput, endOutput, export, finished, flush, flushControlled, flushData, forcePageBreak, forcePageBreak, generateStringFormat, getAvailableLines, getControl, getConvert, getDelimiter, getDisplayMode, getEcho, getEffectivePageSize, getLength, getName, getNextLineNum, getPageNum, getPageSize, getPendingRowCount, getPosition, getPulseOnClose, getUnformatted, hasPageHeadersFooters, indexOfNewLine, isContiguous, isFreshPage, isSilent, isSuppressFormFeed, isTerm, isUnbuffered, isUnnamed, isValid, iterate, needsHeadersOutput, needsPageBreak, needsPageBreak, processFooters, processHeaders, processHeadersInt, processHeadersUncond, protectReads, protectWrites, pulseOutput, put, putControl, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putLineEnd, putLineEnd, putNull, putNull, putSpace, putSpace, putUnformatted, putWorker, rawGetNextLineNum, rawGetPageNum, rawGetPageSize, rawIncrementNextLineNum, rawIncrementPageNum, rawNextLineNum, rawPageSize, rawResetNextLineNum, readBlock, readChar, readChar, readChunk, readField, readField, readField, readField, readFieldWorker, readLine, readLineCleanup, registerAdvanceListener, registerCloseListener, registerFlushListener, registerFooter, registerHeader, registerPageBreakListener, resetCurrentLine, retry, setAppend, setBinary, setContiguous, setControl, setConvert, setConvertSource, setConvertSource, setConvertTarget, setConvertTarget, setDelimiter, setDelimiter, setEcho, setFont, setFont, setLandscape, setName, setPageSize, setPageSize, setPageSize, setPendingRowCount, setPortrait, setPosition, setPosition, setPulseOnClose, setUnbuffered, setUnformatted, setUnnamed, skipField, skipLoneHyphenInput, startOutput, writeBlock, writeControlled, writeControlledSpecial, writeField, writeField, writeField, writeField, writeField
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initFailure
private boolean outputStarted
private ChuiOutputManager tk
private BasePrimitives worker
private char[] buffer
private int rows
private int cols
private int start
private int cursor
void rawSetPageSize(int sz)
rawSetPageSize
in class Stream
sz
- The number of lines per page.public void assign(Stream stream) throws java.lang.UnsupportedOperationException
public long available() throws java.io.IOException
public void close()
public void closeIn()
public void closeOut()
public long getLen() throws java.lang.UnsupportedOperationException, java.io.IOException
public long getPos() throws java.lang.UnsupportedOperationException, java.io.IOException
public boolean isIn()
public boolean isOut()
public int peekCh()
public int readCh()
public java.lang.String readLn() throws java.io.EOFException, java.io.IOException, java.lang.InterruptedException
File.separator
or to the EOF
. Any line separator character(s) and the
EOF
character are not returned. In actuality this has no
effect.readLn
in class Stream
EOFException
.java.io.EOFException
- If this input stream reaches the end before reading all the bytes.java.io.IOException
- If an I/O error occurs.java.lang.InterruptedException
- If any thread interrupted the current thread before or while
the current thread was waiting for a notification.public void setLen(long len) throws java.lang.UnsupportedOperationException, java.io.IOException
public void setPos(long pos) throws java.lang.UnsupportedOperationException, java.io.IOException
public void write(java.lang.String data) throws java.io.IOException
public void write(byte[] data) throws java.io.IOException
public void write(byte[] data, int off, int len) throws java.io.IOException
write
in class Stream
data
- The data to be written.off
- Starting offset in data from which to read bytes to be written. Must be
non-negative and < data.length
.len
- Length of data to be written. Must be non-negative and <= (data.length
- offset)
.java.io.IOException
- If an I/O error occurs.public void writeByte(byte b) throws java.io.IOException
public void writeCh(char ch) throws java.io.IOException
private void teletype(char ch)
ch
- Character to write to the stream.private void insertFormFeed()
private void syncTeletype(char ch)
ch
- Character to write to the stream.private void syncTeletypeString(java.lang.String data)
data
- The characters to write to the stream.private void refreshScreen()
private void refreshRow(int row)
row
- Row number to refresh.