public abstract class UnixLikeTerminal extends ANSITerminal
UnixTerminal
and CygwinTerminal
, like setting tty modes; echo, cbreak
and minimum characters for reading as well as a shutdown hook to set the tty back to
original state at the end.
If requested, it handles Control-C input to terminate the program, and hooks into Unix WINCH signal to detect when the user has resized the terminal, if supported by the JVM.
Modifier and Type | Class and Description |
---|---|
static class |
UnixLikeTerminal.CtrlCBehaviour
This enum lets you control how Lanterna will handle a ctrl+c keystroke from the user.
|
Modifier and Type | Field and Description |
---|---|
protected UnixLikeTerminal.CtrlCBehaviour |
terminalCtrlCBehaviour |
protected File |
ttyDev |
Constructor and Description |
---|
UnixLikeTerminal(InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset,
UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour,
File ttyDev)
Creates a UnixTerminal using a specified input stream, output stream and character set, with a custom size
querier instead of using the default one.
|
Modifier and Type | Method and Description |
---|---|
protected String |
exec(String... cmd) |
KeyStroke |
pollInput()
Returns the next
Key off the input queue or null if there is no more input events available. |
KeyStroke |
readInput()
Returns the next
Key off the input queue or blocks until one is available. |
protected void |
restoreSTTY() |
protected void |
saveSTTY() |
void |
setCBreak(boolean cbreakOn)
Enabling cbreak mode will allow you to read user input immediately as the user enters the characters, as opposed
to reading the data in lines as the user presses enter.
|
void |
setEcho(boolean echoOn)
Enables or disables keyboard echo, meaning the immediate output of the characters you type on your keyboard.
|
protected void |
setupShutdownHook() |
protected void |
setupWinResizeHandler() |
protected abstract void |
sttyICanon(boolean enable) |
protected abstract void |
sttyKeyEcho(boolean enable) |
protected abstract void |
sttyMinimum1CharacterForRead() |
protected abstract void |
sttyRestore(String tok) |
protected abstract String |
sttySave() |
clearScreen, deiconify, disableSGR, enableSGR, enterPrivateMode, exitPrivateMode, getDefaultKeyDecodingProfile, getTerminalSize, iconify, maximize, popTitle, pushTitle, resetColorAndSGR, scrollLines, setBackgroundColor, setCursorPosition, setCursorVisible, setForegroundColor, setMouseCaptureMode, setTerminalSize, setTitle, unmaximize
addKeyDecodingProfile, enquireTerminal, flush, getCharset, getInputDecoder, putCharacter, translateCharacter, writeToTerminal
addResizeListener, newTextGraphics, onResized, removeResizeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addResizeListener, enquireTerminal, flush, newTextGraphics, putCharacter, removeResizeListener
protected final UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour
protected final File ttyDev
public UnixLikeTerminal(InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset, UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour, File ttyDev)
terminalInput
- Input stream to read terminal input fromterminalOutput
- Output stream to write terminal output toterminalCharset
- Character set to use when converting characters to bytesterminalCtrlCBehaviour
- Special settings on how the terminal will behave, see UnixTerminalMode
for more
detailsttyDev
- File to redirect standard input from in exec(), if not null.protected String exec(String... cmd) throws IOException
IOException
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.pollInput
in interface InputProvider
pollInput
in class ANSITerminal
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.readInput
in interface InputProvider
readInput
in class ANSITerminal
IOException
- Propagated error if the underlying stream gave errorsprotected void setupWinResizeHandler()
protected void setupShutdownHook()
public void setCBreak(boolean cbreakOn) throws IOException
cbreakOn
- Should cbreak be turned on or notIOException
public void setEcho(boolean echoOn) throws IOException
echoOn
- true if keyboard input will immediately echo, false if it's hiddenIOException
protected void saveSTTY() throws IOException
IOException
protected void restoreSTTY() throws IOException
IOException
protected abstract void sttyKeyEcho(boolean enable) throws IOException
IOException
protected abstract void sttyMinimum1CharacterForRead() throws IOException
IOException
protected abstract void sttyICanon(boolean enable) throws IOException
IOException
protected abstract String sttySave() throws IOException
IOException
protected abstract void sttyRestore(String tok) throws IOException
IOException
Copyright © 2016. All rights reserved.