public class WindowsTerminal extends Terminal
Terminal implementation for Microsoft Windows. Terminal initialization in
initializeTerminal()
is accomplished by extracting the
jline_version.dll, saving it to the system temporary
directoy (determined by the setting of the java.io.tmpdir System
property), loading the library, and then calling the Win32 APIs SetConsoleMode and
GetConsoleMode to
disable character echoing.
By default, the readCharacter(java.io.InputStream)
method will attempt to test to see if
the specified InputStream
is System.in
or a wrapper around
FileDescriptor.in
, and if so, will bypass the character reading to
directly invoke the readc() method in the JNI library. This is so the class
can read special keys (like arrow keys) which are otherwise inaccessible via
the System.in
stream. Using JNI reading can be bypassed by setting
the jline.WindowsTerminal.disableDirectConsole
system property
to true
.
Modifier and Type | Field and Description |
---|---|
static int |
DELETE_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates that
the delete key was pressed.
|
static int |
DOWN_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates an
down arrow key press.
|
static char |
END_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates that
the end key was pressed.
|
static char |
ESCAPE_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR,
this character indicates that the escape key was pressed.
|
static int |
HOME_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates that
the home key was pressed.
|
static char |
INSERT_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates that
the insert key was pressed.
|
static int |
LEFT_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR,
this character indicates an left arrow key press.
|
static int |
NUMPAD_KEY_INDICATOR
On windows terminals, this character indicates that a special key on the
number pad has been pressed.
|
static char |
PAGE_DOWN_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates that
the page down key was pressed.
|
static char |
PAGE_UP_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates that
the page up key was pressed.
|
static int |
RIGHT_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates an
right arrow key press.
|
static int |
SPECIAL_KEY_INDICATOR
On windows terminals, this character indicates that a 'special' key has
been pressed.
|
static int |
UP_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR
this character indicates an up
arrow key press.
|
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, INTERRUPT, 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 and Description |
---|
WindowsTerminal() |
Modifier and Type | Method and Description |
---|---|
void |
disableEcho()
Disable character echoing.
|
void |
enableEcho()
Enable character echoing.
|
InputStream |
getDefaultBindings() |
Boolean |
getDirectConsole()
Whether or not to allow the use of the JNI console interaction.
|
boolean |
getEcho()
Returns true if the terminal will echo all characters type.
|
int |
getTerminalHeight()
Unsupported; return the default.
|
int |
getTerminalWidth()
Unsupported; return the default.
|
void |
initializeTerminal()
Initialize any system settings
that are required for the console to be able to handle
input correctly, such as setting tabtop, buffered input, and
character echo.
|
boolean |
isANSISupported()
Windows doesn't support ANSI codes by default; disable them.
|
boolean |
isEchoEnabled()
Returns false if character echoing is disabled.
|
boolean |
isSupported()
Returns true if this terminal is capable of initializing the
terminal to use jline.
|
int |
readCharacter(InputStream in)
Read a single character from the input stream.
|
int |
readVirtualKey(InputStream in)
Reads a virtual key from the console.
|
void |
setDirectConsole(Boolean directConsole)
Whether or not to allow the use of the JNI console interaction.
|
afterReadLine, beforeReadLine, getTerminal, resetTerminal, setupTerminal
public static final int SPECIAL_KEY_INDICATOR
public static final int NUMPAD_KEY_INDICATOR
public static final int LEFT_ARROW_KEY
public static final int RIGHT_ARROW_KEY
public static final int UP_ARROW_KEY
public static final int DOWN_ARROW_KEY
public static final int DELETE_KEY
public static final int HOME_KEY
public static final char END_KEY
public static final char PAGE_UP_KEY
public static final char PAGE_DOWN_KEY
public static final char INSERT_KEY
public static final char ESCAPE_KEY
public int readCharacter(InputStream in) throws IOException
Terminal
readCharacter
in class Terminal
IOException
public void initializeTerminal() throws Exception
Terminal
initializeTerminal
in class Terminal
Exception
public int readVirtualKey(InputStream in) throws IOException
Terminal
readVirtualKey
in class Terminal
in
- the InputStream to read fromConsoleOperations#VK_UP
)IOException
public boolean isSupported()
Terminal
isSupported
in class Terminal
public boolean isANSISupported()
isANSISupported
in class Terminal
public boolean getEcho()
Terminal
public int getTerminalWidth()
getTerminalWidth
in class Terminal
Terminal.getTerminalWidth()
public int getTerminalHeight()
getTerminalHeight
in class Terminal
Terminal.getTerminalHeight()
public void setDirectConsole(Boolean directConsole)
public Boolean getDirectConsole()
public boolean isEchoEnabled()
Terminal
isEchoEnabled
in class Terminal
public void enableEcho()
Terminal
enableEcho
in class Terminal
public void disableEcho()
Terminal
disableEcho
in class Terminal
public InputStream getDefaultBindings()
getDefaultBindings
in class Terminal
Copyright © 2024. All rights reserved.