InputProvider
, Terminal
, Closeable
, AutoCloseable
ANSITerminal
public abstract class StreamBasedTerminal extends AbstractTerminal
Constructor | Description |
---|---|
StreamBasedTerminal(InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset) |
Modifier and Type | Method | Description |
---|---|---|
void |
addKeyDecodingProfile(KeyDecodingProfile profile) |
Deprecated.
Use
getInputDecoder().addProfile(profile) instead |
void |
bell() |
Prints 0x7 to the terminal, which will make the terminal (emulator) ring a bell (or more likely beep).
|
void |
close() |
Closes the terminal, if applicable.
|
byte[] |
enquireTerminal(int timeout,
TimeUnit timeoutTimeUnit) |
Retrieves optional information from the terminal by printing the ENQ (\u005) character.
|
void |
flush() |
Calls
flush() on the underlying OutputStream object, or whatever other implementation this
terminal is built around. |
protected Charset |
getCharset() |
|
InputDecoder |
getInputDecoder() |
Returns the
InputDecoder attached to this StreamBasedTerminal . |
KeyStroke |
pollInput() |
Returns the next
Key off the input queue or null if there is no more input events available. |
void |
putCharacter(char c) |
Prints one character to the terminal at the current cursor location.
|
KeyStroke |
readInput() |
Returns the next
Key off the input queue or blocks until one is available. |
protected byte[] |
translateCharacter(char input) |
|
protected void |
writeToTerminal(byte... bytes) |
This method will write a list of bytes directly to the output stream of the terminal.
|
addResizeListener, newTextGraphics, onResized, onResized, removeResizeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearScreen, disableSGR, enableSGR, enterPrivateMode, exitPrivateMode, getCursorPosition, getTerminalSize, resetColorAndSGR, setBackgroundColor, setCursorPosition, setCursorPosition, setCursorVisible, setForegroundColor
public StreamBasedTerminal(InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset)
public void putCharacter(char c) throws IOException
putCharacter
will print out a text string without the need
to reposition the text cursor. If you reach the end of the line while putting characters using this method, you
can expect the text cursor to move to the beginning of the next line.
You can output CJK (Chinese, Japanese, Korean) characters (as well as other regional scripts) but remember that
the terminal that the user is using might not have the required font to render it. Also worth noticing is that
CJK (and some others) characters tend to take up 2 columns per character, simply because they are a square in
their construction as opposed to the somewhat rectangular shape we fit latin characters in. As it's very
difficult to create a monospace font for CJK with a 2:1 height-width proportion, it seems like the implementers
back in the days simply gave up and made each character take 2 column. It causes issues for the random terminal
programmer because you can't really trust 1 character = 1 column, but I suppose it's "しょうがない".
If you try to print non-printable control characters, the terminal is likely to ignore them (all Terminal
implementations bundled with Lanterna will).
The StreamBasedTerminal
class will attempt to translate some unicode characters to VT100 if the encoding
attached to this Terminal
isn't UTF-8.
c
- Character to place on the terminalIOException
- If there was an underlying I/O errorprotected void writeToTerminal(byte... bytes) throws IOException
bytes
- Bytes to write to the terminal (synchronized)IOException
- If there was an underlying I/O errorpublic byte[] enquireTerminal(int timeout, TimeUnit timeoutTimeUnit) throws IOException
Terminal
timeout
- How long to wait for the talk-back message, if there's nothing immediately available on the input
stream, you should probably set this to a somewhat small value to prevent unnecessary blockage on the input stream
but large enough to accommodate a round-trip to the user's terminal (~300 ms if you are connection across the globe).timeoutTimeUnit
- What unit to use when interpreting the timeout
parameterIOException
- If there was an I/O error while trying to read the enquiry replypublic void bell() throws IOException
Terminal
IOException
- If there was an underlying I/O error@Deprecated public void addKeyDecodingProfile(KeyDecodingProfile profile)
getInputDecoder().addProfile(profile)
insteadKey
objects.profile
- Decoding profile to addKeyDecodingProfile
public InputDecoder getInputDecoder()
InputDecoder
attached to this StreamBasedTerminal
. Can be used to add additional
character patterns to recognize and tune the way input is turned in KeyStroke
:s.InputDecoder
attached to this StreamBasedTerminal
public KeyStroke pollInput() throws IOException
InputProvider
Key
off the input queue or null if there is no more input events available. Note, this
method call is not blocking, it returns null immediately if there is nothing on the input stream.IOException
- Propagated error if the underlying stream gave errorspublic KeyStroke readInput() throws IOException
InputProvider
Key
off the input queue or blocks until one is available. NOTE: In previous
versions of Lanterna, this method was not blocking. From lanterna 3, it is blocking and you can call
pollInput()
for the non-blocking version.IOException
- Propagated error if the underlying stream gave errorspublic void flush() throws IOException
Terminal
flush()
on the underlying OutputStream
object, or whatever other implementation this
terminal is built around. Some implementing classes of this interface (like SwingTerminal) doesn't do anything
as it doesn't really apply to them.IOException
- If there was an underlying I/O errorpublic void close() throws IOException
Terminal
IOException
- If there was an underlying I/O errorprotected Charset getCharset()
protected byte[] translateCharacter(char input)
Copyright © 2020. All rights reserved.