Module com.googlecode.lanterna
Class UnixLikeTTYTerminal
- java.lang.Object
-
- com.googlecode.lanterna.terminal.AbstractTerminal
-
- com.googlecode.lanterna.terminal.ansi.StreamBasedTerminal
-
- com.googlecode.lanterna.terminal.ansi.ANSITerminal
-
- com.googlecode.lanterna.terminal.ansi.UnixLikeTerminal
-
- com.googlecode.lanterna.terminal.ansi.UnixLikeTTYTerminal
-
- All Implemented Interfaces:
Scrollable
,InputProvider
,ExtendedTerminal
,Terminal
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
CygwinTerminal
,UnixTerminal
public abstract class UnixLikeTTYTerminal extends UnixLikeTerminal
UnixLikeTerminal extends from ANSITerminal and defines functionality that is common toUnixTerminal
andCygwinTerminal
, 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.googlecode.lanterna.terminal.ansi.UnixLikeTerminal
UnixLikeTerminal.CtrlCBehaviour
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
sttyStatusToRestore
private java.io.File
ttyDev
-
Constructor Summary
Constructors Modifier Constructor Description protected
UnixLikeTTYTerminal(java.io.File ttyDev, java.io.InputStream terminalInput, java.io.OutputStream terminalOutput, java.nio.charset.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.
-
Method Summary
All Methods Instance Methods Concrete Methods 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 java.lang.String
exec(java.lang.String... cmd)
private java.lang.String
getSTTYCommand()
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 regularKeyStroke
instead of as a signal to the JVM process.private void
realAcquire()
protected void
registerTerminalResizeListener(java.lang.Runnable onResize)
protected void
restoreTerminalSettings()
Restores the terminal settings from last timeUnixLikeTerminal.saveTerminalSettings()
was calledprotected java.lang.String
runSTTYCommand(java.lang.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 usingUnixLikeTerminal.restoreTerminalSettings()
-
Methods inherited from class com.googlecode.lanterna.terminal.ansi.UnixLikeTerminal
close, getTerminalCtrlCBehaviour, pollInput, readInput
-
Methods inherited from class com.googlecode.lanterna.terminal.ansi.ANSITerminal
clearScreen, deiconify, disableSGR, enableSGR, enterPrivateMode, exitPrivateMode, findTerminalSize, getCursorPosition, getDefaultKeyDecodingProfile, getTerminalSize, iconify, isInPrivateMode, maximize, popTitle, pushTitle, reportPosition, resetColorAndSGR, restoreCursorPosition, saveCursorPosition, scrollLines, setBackgroundColor, setCursorPosition, setCursorPosition, setCursorVisible, setForegroundColor, setMouseCaptureMode, setTerminalSize, setTitle, unmaximize
-
Methods inherited from class com.googlecode.lanterna.terminal.ansi.StreamBasedTerminal
bell, enquireTerminal, flush, getCharset, getInputDecoder, putCharacter, putString, resetMemorizedCursorPosition, translateCharacter, waitForCursorPositionReport, writeToTerminal
-
Methods inherited from class com.googlecode.lanterna.terminal.AbstractTerminal
addResizeListener, newTextGraphics, onResized, onResized, removeResizeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.googlecode.lanterna.terminal.Terminal
addResizeListener, bell, enquireTerminal, flush, newTextGraphics, putCharacter, putString, removeResizeListener
-
-
-
-
Constructor Detail
-
UnixLikeTTYTerminal
protected UnixLikeTTYTerminal(java.io.File ttyDev, java.io.InputStream terminalInput, java.io.OutputStream terminalOutput, java.nio.charset.Charset terminalCharset, UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour) throws java.io.IOException
Creates a UnixTerminal using a specified input stream, output stream and character set, with a custom size querier instead of using the default one. This way you can override size detection (if you want to force the terminal to a fixed size, for example). You also choose how you want ctrl+c key strokes to be handled.- Parameters:
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, seeUnixTerminalMode
for more details- Throws:
java.io.IOException
- If there was an I/O error while setting up the terminal
-
-
Method Detail
-
acquire
protected void acquire() throws java.io.IOException
Description copied from class:UnixLikeTerminal
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. This should be called automatically by the constructor of any end-user class extending fromUnixLikeTerminal
- Overrides:
acquire
in classUnixLikeTerminal
- Throws:
java.io.IOException
- If there was an I/O error
-
realAcquire
private void realAcquire() throws java.io.IOException
- Throws:
java.io.IOException
-
registerTerminalResizeListener
protected void registerTerminalResizeListener(java.lang.Runnable onResize) throws java.io.IOException
- Specified by:
registerTerminalResizeListener
in classUnixLikeTerminal
- Throws:
java.io.IOException
-
saveTerminalSettings
protected void saveTerminalSettings() throws java.io.IOException
Description copied from class:UnixLikeTerminal
Stores the current terminal device settings (the ones that are modified through this interface) so that they can be restored later usingUnixLikeTerminal.restoreTerminalSettings()
- Specified by:
saveTerminalSettings
in classUnixLikeTerminal
- Throws:
java.io.IOException
- If there was an I/O error when altering the terminal environment
-
restoreTerminalSettings
protected void restoreTerminalSettings() throws java.io.IOException
Description copied from class:UnixLikeTerminal
Restores the terminal settings from last timeUnixLikeTerminal.saveTerminalSettings()
was called- Specified by:
restoreTerminalSettings
in classUnixLikeTerminal
- Throws:
java.io.IOException
- If there was an I/O error when altering the terminal environment
-
keyEchoEnabled
protected void keyEchoEnabled(boolean enabled) throws java.io.IOException
Description copied from class:UnixLikeTerminal
Enables or disable key echo mode, which means when the user press a key, the terminal will immediately print that key to the terminal. Normally for Lanterna, this should be turned off so the software can take the key as an input event, put it on the input queue and then depending on the code decide what to do with it.- Specified by:
keyEchoEnabled
in classUnixLikeTerminal
- Parameters:
enabled
-true
if key echo should be enabled,false
otherwise- Throws:
java.io.IOException
- If there was an I/O error when altering the terminal environment
-
canonicalMode
protected void canonicalMode(boolean enabled) throws java.io.IOException
Description copied from class:UnixLikeTerminal
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. This is usually the default mode for a terminal. Lanterna wants to read each character as they are typed, without waiting for the final newline, so it will attempt to turn canonical mode off on initialization.- Specified by:
canonicalMode
in classUnixLikeTerminal
- Parameters:
enabled
-true
if canonical input mode should be enabled,false
otherwise- Throws:
java.io.IOException
- If there was an I/O error when altering the terminal environment
-
keyStrokeSignalsEnabled
protected void keyStrokeSignalsEnabled(boolean enabled) throws java.io.IOException
Description copied from class:UnixLikeTerminal
This method causes certain keystrokes (at the moment only ctrl+c) to be passed in to the program as a regularKeyStroke
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 regularKeyStroke
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".
- Specified by:
keyStrokeSignalsEnabled
in classUnixLikeTerminal
- Parameters:
enabled
- Pass intrue
if you want keystrokes to generate system signals (like process interrupt),false
if you want lanterna to catch and interpret these keystrokes are regular keystrokes- Throws:
java.io.IOException
- If there was an I/O error when attempting to disable special characters- See Also:
UnixLikeTerminal.CtrlCBehaviour
-
runSTTYCommand
protected java.lang.String runSTTYCommand(java.lang.String... parameters) throws java.io.IOException
- Throws:
java.io.IOException
-
exec
protected java.lang.String exec(java.lang.String... cmd) throws java.io.IOException
- Throws:
java.io.IOException
-
getSTTYCommand
private java.lang.String getSTTYCommand()
-
-