Package jline
Class UnixTerminal
- java.lang.Object
-
- jline.Terminal
-
- jline.UnixTerminal
-
- All Implemented Interfaces:
ConsoleOperations
public class UnixTerminal extends Terminal
Terminal that is used for unix platforms. Terminal initialization is handled by issuing the stty command against the /dev/tty file to disable character echoing and enable character input. All known unix systems (including Linux and Macintosh OS X) support the stty), so this implementation should work for an reasonable POSIX system.
- Author:
- Marc Prud'hommeaux, Updates Dale Kemp 2005-12-03
-
-
Field Summary
Fields Modifier and Type Field Description static shortARROW_DOWNstatic shortARROW_LEFTstatic shortARROW_PREFIXstatic shortARROW_RIGHTstatic shortARROW_STARTstatic shortARROW_UPstatic shortDEL_SECONDstatic shortDEL_THIRDstatic shortEND_CODEstatic shortHOME_CODEstatic shortO_PREFIX-
Fields inherited from interface jline.ConsoleOperations
ABORT, ADD, BACKSPACE, CHANGE_CASE, CHANGE_META, CLEAR_LINE, CLEAR_SCREEN, COMPLETE, CR, CTRL_A, CTRL_B, CTRL_C, CTRL_D, CTRL_E, CTRL_F, CTRL_G, CTRL_K, CTRL_L, CTRL_N, CTRL_OB, CTRL_P, CTRL_QM, DELETE, DELETE_META, DELETE_NEXT_CHAR, DELETE_PREV_CHAR, DELETE_PREV_WORD, END_OF_HISTORY, END_WORD, EXIT, INSERT, KEYBOARD_BELL, KILL_LINE, KILL_LINE_PREV, MOVE_TO_BEG, MOVE_TO_END, NEWLINE, NEXT_CHAR, NEXT_HISTORY, NEXT_SPACE_WORD, NEXT_WORD, PASTE, PASTE_NEXT, PASTE_PREV, PREV_CHAR, PREV_HISTORY, PREV_SPACE_WORD, PREV_WORD, REDISPLAY, REPEAT_NEXT_CHAR, REPEAT_PREV_CHAR, REPEAT_SEARCH_NEXT, REPEAT_SEARCH_PREV, REPLACE_CHAR, REPLACE_MODE, RESET_LINE, SEARCH_NEXT, SEARCH_PREV, START_OF_HISTORY, SUBSTITUTE_CHAR, SUBSTITUTE_LINE, TO_END_WORD, TO_NEXT_CHAR, TO_PREV_CHAR, UNDO, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description UnixTerminal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckBackspace()voiddisableEcho()Disable character echoing.voidenableEcho()Enable character echoing.booleangetEcho()Returns true if the terminal will echo all characters type.static java.lang.StringgetSttyCommand()The command to use to set the terminal options.intgetTerminalHeight()Returns the value of "stty size" height param.intgetTerminalWidth()Returns the value of "stty size" width param.voidinitializeTerminal()Remove line-buffered input by invoking "stty -icanon min 1" against the current terminal.booleanisEchoEnabled()Returns false if character echoing is disabled.booleanisSupported()Returns true if this terminal is capable of initializing the terminal to use jline.intreadVirtualKey(java.io.InputStream in)Reads a virtual key from the console.voidrestoreTerminal()Restore the original terminal configuration, which can be used when shutting down the console reader.static voidsetSttyCommand(java.lang.String cmd)The command to use to set the terminal options.protected static java.lang.Stringstty(java.lang.String args)Execute the stty command with the specified arguments against the current active terminal.-
Methods inherited from class jline.Terminal
afterReadLine, beforeReadLine, getDefaultBindings, getTerminal, isANSISupported, readCharacter, resetTerminal, setupTerminal
-
-
-
-
Field Detail
-
ARROW_START
public static final short ARROW_START
- See Also:
- Constant Field Values
-
ARROW_PREFIX
public static final short ARROW_PREFIX
- See Also:
- Constant Field Values
-
ARROW_LEFT
public static final short ARROW_LEFT
- See Also:
- Constant Field Values
-
ARROW_RIGHT
public static final short ARROW_RIGHT
- See Also:
- Constant Field Values
-
ARROW_UP
public static final short ARROW_UP
- See Also:
- Constant Field Values
-
ARROW_DOWN
public static final short ARROW_DOWN
- See Also:
- Constant Field Values
-
O_PREFIX
public static final short O_PREFIX
- See Also:
- Constant Field Values
-
HOME_CODE
public static final short HOME_CODE
- See Also:
- Constant Field Values
-
END_CODE
public static final short END_CODE
- See Also:
- Constant Field Values
-
DEL_THIRD
public static final short DEL_THIRD
- See Also:
- Constant Field Values
-
DEL_SECOND
public static final short DEL_SECOND
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkBackspace
protected void checkBackspace()
-
initializeTerminal
public void initializeTerminal() throws java.io.IOException, java.lang.InterruptedExceptionRemove line-buffered input by invoking "stty -icanon min 1" against the current terminal.- Specified by:
initializeTerminalin classTerminal- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
restoreTerminal
public void restoreTerminal() throws java.lang.ExceptionRestore the original terminal configuration, which can be used when shutting down the console reader. The ConsoleReader cannot be used after calling this method.- Throws:
java.lang.Exception
-
readVirtualKey
public int readVirtualKey(java.io.InputStream in) throws java.io.IOExceptionDescription copied from class:TerminalReads a virtual key from the console. Typically, this will just be the raw character that was entered, but in some cases, multiple input keys will need to be translated into a single virtual key.- Overrides:
readVirtualKeyin classTerminal- Parameters:
in- the InputStream to read from- Returns:
- the virtual key (e.g.,
ConsoleOperations#VK_UP) - Throws:
java.io.IOException
-
isSupported
public boolean isSupported()
Description copied from class:TerminalReturns true if this terminal is capable of initializing the terminal to use jline.- Specified by:
isSupportedin classTerminal
-
getEcho
public boolean getEcho()
Description copied from class:TerminalReturns true if the terminal will echo all characters type.
-
getTerminalWidth
public int getTerminalWidth()
Returns the value of "stty size" width param. Note: this method caches the value from the first time it is called in order to increase speed, which means that changing to size of the terminal will not be reflected in the console.- Specified by:
getTerminalWidthin classTerminal
-
getTerminalHeight
public int getTerminalHeight()
Returns the value of "stty size" height param. Note: this method caches the value from the first time it is called in order to increase speed, which means that changing to size of the terminal will not be reflected in the console.- Specified by:
getTerminalHeightin classTerminal
-
stty
protected static java.lang.String stty(java.lang.String args) throws java.io.IOException, java.lang.InterruptedExceptionExecute the stty command with the specified arguments against the current active terminal.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
setSttyCommand
public static void setSttyCommand(java.lang.String cmd)
The command to use to set the terminal options. Defaults to "stty", or the value of the system property "jline.sttyCommand".
-
getSttyCommand
public static java.lang.String getSttyCommand()
The command to use to set the terminal options. Defaults to "stty", or the value of the system property "jline.sttyCommand".
-
isEchoEnabled
public boolean isEchoEnabled()
Description copied from class:TerminalReturns false if character echoing is disabled.- Specified by:
isEchoEnabledin classTerminal
-
enableEcho
public void enableEcho()
Description copied from class:TerminalEnable character echoing. This can be used to re-enable character if the ConsoleReader is no longer being used.- Specified by:
enableEchoin classTerminal
-
disableEcho
public void disableEcho()
Description copied from class:TerminalDisable character echoing. This can be used to manually re-enable character if the ConsoleReader has been disabled.- Specified by:
disableEchoin classTerminal
-
-