jline

Class UnixTerminal

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.
Authors:
Marc Prud'hommeaux
Updates Dale Kemp 2005-12-03

Nested Class Summary

(package private) static class
UnixTerminal.ReplayPrefixOneCharInputStream
This is awkward and inefficient, but probably the minimal way to add UTF-8 support to JLine

Field Summary

static short
ARROW_DOWN
static short
ARROW_LEFT
static short
ARROW_PREFIX
static short
ARROW_RIGHT
static short
ARROW_START
static short
ARROW_UP
static short
DEL_SECOND
static short
DEL_THIRD
static short
END_CODE
static short
HOME_CODE
static short
O_PREFIX
private boolean
backspaceDeleteSwitched
private boolean
echoEnabled
(package private) String
encoding
(package private) InputStreamReader
replayReader
(package private) UnixTerminal.ReplayPrefixOneCharInputStream
replayStream
private static String
sttyCommand
private Map
terminfo
private String
ttyConfig

Fields inherited from class jline.Terminal

term

Fields inherited from interface jline.ConsoleOperations

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_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

UnixTerminal()

Method Summary

protected void
checkBackspace()
private void
consumeException(Throwable e)
No-op for exceptions we want to silently consume.
void
disableEcho()
void
enableEcho()
private static String
exec(String cmd)
Execute the specified command and return the output (both stdout and stderr).
private static String
exec(String[] cmd)
Execute the specified command and return the output (both stdout and stderr).
boolean
getEcho()
static String
getSttyCommand()
The command to use to set the terminal options.
int
getTerminalHeight()
Returns the value of "stty size" height param.
private static int
getTerminalProperty(String prop)
int
getTerminalWidth()
Returns the value of "stty size" width param.
void
initializeTerminal()
Remove line-buffered input by invoking "stty -icanon min 1" against the current terminal.
boolean
isEchoEnabled()
boolean
isSupported()
int
readVirtualKey(InputStream in)
void
restoreTerminal()
Restore the original terminal configuration, which can be used when shutting down the console reader.
static void
setSttyCommand(String cmd)
The command to use to set the terminal options.
private static String
stty(String args)
Execute the stty command with the specified arguments against the current active terminal.

Methods inherited from class jline.Terminal

afterReadLine, beforeReadLine, disableEcho, enableEcho, getDefaultBindings, getEcho, getTerminal, getTerminalHeight, getTerminalWidth, initializeTerminal, isANSISupported, isEchoEnabled, isSupported, readCharacter, readVirtualKey, resetTerminal, setupTerminal

Field Details

ARROW_DOWN

public static final short ARROW_DOWN
Field Value:
66

ARROW_LEFT

public static final short ARROW_LEFT
Field Value:
68

ARROW_PREFIX

public static final short ARROW_PREFIX
Field Value:
91

ARROW_RIGHT

public static final short ARROW_RIGHT
Field Value:
67

ARROW_START

public static final short ARROW_START
Field Value:
27

ARROW_UP

public static final short ARROW_UP
Field Value:
65

DEL_SECOND

public static final short DEL_SECOND
Field Value:
126

DEL_THIRD

public static final short DEL_THIRD
Field Value:
51

END_CODE

public static final short END_CODE
Field Value:
70

HOME_CODE

public static final short HOME_CODE
Field Value:
72

O_PREFIX

public static final short O_PREFIX
Field Value:
79

backspaceDeleteSwitched

private boolean backspaceDeleteSwitched

echoEnabled

private boolean echoEnabled

encoding

(package private)  String encoding

replayReader

(package private)  InputStreamReader replayReader

replayStream

(package private)  UnixTerminal.ReplayPrefixOneCharInputStream replayStream

sttyCommand

private static String sttyCommand

terminfo

private Map terminfo

ttyConfig

private String ttyConfig

Constructor Details

UnixTerminal

public UnixTerminal()

Method Details

checkBackspace

protected void checkBackspace()

consumeException

private void consumeException(Throwable e)
No-op for exceptions we want to silently consume.

disableEcho

public void disableEcho()
Overrides:
disableEcho in interface Terminal

enableEcho

public void enableEcho()
Overrides:
enableEcho in interface Terminal

exec

private static String exec(String cmd)
            throws IOException,
                   InterruptedException
Execute the specified command and return the output (both stdout and stderr).

exec

private static String exec(String[] cmd)
            throws IOException,
                   InterruptedException
Execute the specified command and return the output (both stdout and stderr).

getEcho

public boolean getEcho()
Overrides:
getEcho in interface Terminal

getSttyCommand

public static String getSttyCommand()
The command to use to set the terminal options. Defaults to "stty", or the value of the system property "jline.sttyCommand".

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.
Overrides:
getTerminalHeight in interface Terminal

getTerminalProperty

private static int getTerminalProperty(String prop)
            throws IOException,
                   InterruptedException

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.
Overrides:
getTerminalWidth in interface Terminal

initializeTerminal

public void initializeTerminal()
            throws IOException,
                   InterruptedException
Remove line-buffered input by invoking "stty -icanon min 1" against the current terminal.
Overrides:
initializeTerminal in interface Terminal

isEchoEnabled

public boolean isEchoEnabled()
Overrides:
isEchoEnabled in interface Terminal

isSupported

public boolean isSupported()
Overrides:
isSupported in interface Terminal

readVirtualKey

public int readVirtualKey(InputStream in)
            throws IOException
Overrides:
readVirtualKey in interface Terminal

restoreTerminal

public void restoreTerminal()
            throws Exception
Restore the original terminal configuration, which can be used when shutting down the console reader. The ConsoleReader cannot be used after calling this method.

setSttyCommand

public static void setSttyCommand(String cmd)
The command to use to set the terminal options. Defaults to "stty", or the value of the system property "jline.sttyCommand".

stty

private static String stty(String args)
            throws IOException,
                   InterruptedException
Execute the stty command with the specified arguments against the current active terminal.