public class UnixTerminal extends UnixLikeTerminal
If you need to have Lanterna to call stty at a different location, you'll need to
subclass this and override getSTTYCommand()
.
UnixLikeTerminal.CtrlCBehaviour
Modifier and Type | Field and Description |
---|---|
protected UnixTerminalSizeQuerier |
terminalSizeQuerier |
terminalCtrlCBehaviour, ttyDev
Constructor and Description |
---|
UnixTerminal()
Creates a UnixTerminal with default settings, using System.in and System.out for input/output, using the default
character set on the system as the encoding and trap ctrl+c signal instead of killing the application.
|
UnixTerminal(InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset)
Creates a UnixTerminal using a specified input stream, output stream and character set.
|
UnixTerminal(InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset,
UnixTerminalSizeQuerier customSizeQuerier)
Creates a UnixTerminal using a specified input stream, output stream and character set, with a custom size
querier instead of using the default one.
|
UnixTerminal(InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset,
UnixTerminalSizeQuerier customSizeQuerier,
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 and Description |
---|---|
void |
disableSpecialCharacters()
This method causes certain keystrokes (at the moment only ctrl+c) to be passed in to the program instead of
interpreted by the shell and affect the program.
|
protected String |
getSTTYCommand() |
TerminalSize |
getTerminalSize()
Returns the size of the terminal, expressed as a
TerminalSize object. |
void |
restoreSpecialCharacters()
This method restores the special characters disabled by
disableSpecialCharacters() , if it has been
called. |
protected void |
restoreSTTY() |
protected void |
sttyICanon(boolean enable) |
protected void |
sttyKeyEcho(boolean enable) |
protected void |
sttyMinimum1CharacterForRead() |
protected void |
sttyRestore(String tok) |
protected String |
sttySave() |
exec, pollInput, readInput, saveSTTY, setCBreak, setEcho, setupShutdownHook, setupWinResizeHandler
clearScreen, deiconify, disableSGR, enableSGR, enterPrivateMode, exitPrivateMode, getDefaultKeyDecodingProfile, 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 UnixTerminalSizeQuerier terminalSizeQuerier
public UnixTerminal() throws IOException
IOException
- If there was an I/O error initializing the terminalpublic UnixTerminal(InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset) throws IOException
terminalInput
- Input stream to read terminal input fromterminalOutput
- Output stream to write terminal output toterminalCharset
- Character set to use when converting characters to bytesIOException
- If there was an I/O error initializing the terminalpublic UnixTerminal(InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset, UnixTerminalSizeQuerier customSizeQuerier) throws IOException
terminalInput
- Input stream to read terminal input fromterminalOutput
- Output stream to write terminal output toterminalCharset
- Character set to use when converting characters to bytescustomSizeQuerier
- Object to use for looking up the size of the terminal, or null to use the built-in
methodIOException
- If there was an I/O error initializing the terminalpublic UnixTerminal(InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset, UnixTerminalSizeQuerier customSizeQuerier, UnixLikeTerminal.CtrlCBehaviour terminalCtrlCBehaviour) throws IOException
terminalInput
- Input stream to read terminal input fromterminalOutput
- Output stream to write terminal output toterminalCharset
- Character set to use when converting characters to bytescustomSizeQuerier
- Object to use for looking up the size of the terminal, or null to use the built-in
methodterminalCtrlCBehaviour
- Special settings on how the terminal will behave, see UnixTerminalMode
for more
detailsIOException
- If there was an I/O error initializing the terminalpublic TerminalSize getTerminalSize() throws IOException
Terminal
TerminalSize
object. Please bear in mind that depending
on the Terminal
implementation, this may or may not be accurate. See the implementing classes for more
information. Most commonly, calling getTerminalSize() will involve some kind of hack to retrieve the size of the
terminal, like moving the cursor to position 5000x5000 and then read back the location, unless the terminal
implementation has a more smooth way of getting this data. Keep this in mind and see if you can avoid calling
this method too often. There is a helper class, SimpleTerminalResizeListener, that you can use to cache the size
and update it only when resize events are received (which depends on if a resize is detectable, which they are not
on all platforms).getTerminalSize
in interface Terminal
getTerminalSize
in class ANSITerminal
IOException
- if there was an I/O error trying to retrieve the size of the terminalprotected void sttyKeyEcho(boolean enable) throws IOException
sttyKeyEcho
in class UnixLikeTerminal
IOException
protected void sttyMinimum1CharacterForRead() throws IOException
sttyMinimum1CharacterForRead
in class UnixLikeTerminal
IOException
protected void sttyICanon(boolean enable) throws IOException
sttyICanon
in class UnixLikeTerminal
IOException
protected String sttySave() throws IOException
sttySave
in class UnixLikeTerminal
IOException
protected void sttyRestore(String tok) throws IOException
sttyRestore
in class UnixLikeTerminal
IOException
public void disableSpecialCharacters() throws IOException
Please note that this method is generally called automatically (i.e. it's turned on by default), unless you define a system property "com.googlecode.lanterna.terminal.UnixTerminal.catchSpecialCharacters" and set it to the string "false".
IOException
- If there was an I/O error when attempting to disable special charactersUnixLikeTerminal.CtrlCBehaviour
public void restoreSpecialCharacters() throws IOException
disableSpecialCharacters()
, if it has been
called.IOException
- If there was an I/O error when attempting to restore special charactersprotected void restoreSTTY() throws IOException
restoreSTTY
in class UnixLikeTerminal
IOException
protected String getSTTYCommand()
Copyright © 2016. All rights reserved.