Scrollable
, InputProvider
, ExtendedTerminal
, Terminal
, Closeable
, AutoCloseable
CygwinTerminal
, UnixTerminal
public abstract class UnixLikeTTYTerminal extends UnixLikeTerminal
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.
UnixLikeTerminal.CtrlCBehaviour
Modifier | Constructor | Description |
---|---|---|
protected |
UnixLikeTTYTerminal(File ttyDev,
InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset,
UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour) |
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 | Description |
---|---|---|
protected void |
acquire() |
Effectively taking over the terminal and enabling it for Lanterna to use, by turning off echo and canonical mode,
adding resize listeners and optionally trap unix signals.
|
protected void |
canonicalMode(boolean enabled) |
In canonical mode, data are accumulated in a line editing buffer, and do not become "available for reading" until
line editing has been terminated by the user sending a line delimiter character.
|
protected String |
exec(String... cmd) |
|
protected void |
keyEchoEnabled(boolean enabled) |
Enables or disable key echo mode, which means when the user press a key, the terminal will immediately print that
key to the terminal.
|
protected void |
keyStrokeSignalsEnabled(boolean enabled) |
This method causes certain keystrokes (at the moment only ctrl+c) to be passed in to the program as a regular
KeyStroke instead of as a signal to the JVM process. |
protected void |
registerTerminalResizeListener(Runnable onResize) |
|
protected void |
restoreTerminalSettings() |
Restores the terminal settings from last time
UnixLikeTerminal.saveTerminalSettings() was called |
protected String |
runSTTYCommand(String... parameters) |
|
protected void |
saveTerminalSettings() |
Stores the current terminal device settings (the ones that are modified through this interface) so that they can
be restored later using
UnixLikeTerminal.restoreTerminalSettings() |
addResizeListener, newTextGraphics, onResized, onResized, removeResizeListener
clearScreen, deiconify, disableSGR, enableSGR, enterPrivateMode, exitPrivateMode, findTerminalSize, getCursorPosition, getDefaultKeyDecodingProfile, getTerminalSize, iconify, maximize, popTitle, pushTitle, resetColorAndSGR, scrollLines, setBackgroundColor, setCursorPosition, setCursorPosition, setCursorVisible, setForegroundColor, setMouseCaptureMode, setTerminalSize, setTitle, unmaximize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addKeyDecodingProfile, bell, enquireTerminal, flush, getCharset, getInputDecoder, putCharacter, translateCharacter, writeToTerminal
addResizeListener, bell, enquireTerminal, flush, newTextGraphics, putCharacter, removeResizeListener
close, getTerminalCtrlCBehaviour, pollInput, readInput
protected UnixLikeTTYTerminal(File ttyDev, InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset, UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour) throws IOException
ttyDev
- TTY device file that is representing this terminal session, will be used when calling stty to make
it operate on this sessionterminalInput
- 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 detailsIOException
- If there was an I/O error while setting up the terminalprotected void acquire() throws IOException
UnixLikeTerminal
UnixLikeTerminal
acquire
in class UnixLikeTerminal
IOException
- If there was an I/O errorprotected void registerTerminalResizeListener(Runnable onResize) throws IOException
registerTerminalResizeListener
in class UnixLikeTerminal
IOException
protected void saveTerminalSettings() throws IOException
UnixLikeTerminal
UnixLikeTerminal.restoreTerminalSettings()
saveTerminalSettings
in class UnixLikeTerminal
IOException
- If there was an I/O error when altering the terminal environmentprotected void restoreTerminalSettings() throws IOException
UnixLikeTerminal
UnixLikeTerminal.saveTerminalSettings()
was calledrestoreTerminalSettings
in class UnixLikeTerminal
IOException
- If there was an I/O error when altering the terminal environmentprotected void keyEchoEnabled(boolean enabled) throws IOException
UnixLikeTerminal
keyEchoEnabled
in class UnixLikeTerminal
enabled
- true
if key echo should be enabled, false
otherwiseIOException
- If there was an I/O error when altering the terminal environmentprotected void canonicalMode(boolean enabled) throws IOException
UnixLikeTerminal
canonicalMode
in class UnixLikeTerminal
enabled
- true
if canonical input mode should be enabled, false
otherwiseIOException
- If there was an I/O error when altering the terminal environmentprotected void keyStrokeSignalsEnabled(boolean enabled) throws IOException
UnixLikeTerminal
KeyStroke
instead of as a signal to the JVM process. For example,
ctrl+c will normally send an interrupt that causes the JVM to shut down, but this method will make it pass
in ctrl+c as a regular KeyStroke
instead. You can of course still
make ctrl+c kill the application through your own input handling if you like.
Please note that this method is called automatically by lanterna to disable signals unless you define a system property "com.googlecode.lanterna.terminal.UnixTerminal.catchSpecialCharacters" and set it to the string "false".
keyStrokeSignalsEnabled
in class UnixLikeTerminal
enabled
- Pass in true
if you want keystrokes to generate system signals (like process interrupt),
false
if you want lanterna to catch and interpret these keystrokes are regular keystrokesIOException
- If there was an I/O error when attempting to disable special charactersUnixLikeTerminal.CtrlCBehaviour
protected String runSTTYCommand(String... parameters) throws IOException
IOException
protected String exec(String... cmd) throws IOException
IOException
Copyright © 2020. All rights reserved.