Class WindowsTerminal
- java.lang.Object
-
- jline.Terminal
-
- jline.WindowsTerminal
-
- All Implemented Interfaces:
ConsoleOperations
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 specifiedInputStreamisSystem.inor a wrapper aroundFileDescriptor.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 theSystem.instream. Using JNI reading can be bypassed by setting thejline.WindowsTerminal.directConsolesystem property tofalse.- Author:
- Marc Prud'hommeaux
-
-
Field Summary
Fields Modifier and Type Field Description static intDELETE_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the delete key was pressed.static intDOWN_ARROW_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an down arrow key press.static charEND_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the end key was pressed.static charESCAPE_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR, this character indicates that the escape key was pressed.static intHOME_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the home key was pressed.static charINSERT_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the insert key was pressed.static intLEFT_ARROW_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR, this character indicates an left arrow key press.static intNUMPAD_KEY_INDICATOROn windows terminals, this character indicates that a special key on the number pad has been pressed.static charPAGE_DOWN_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the page down key was pressed.static charPAGE_UP_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the page up key was pressed.static intRIGHT_ARROW_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an right arrow key press.static intSPECIAL_KEY_INDICATOROn windows terminals, this character indicates that a 'special' key has been pressed.static intUP_ARROW_KEYWhen following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an up arrow key press.-
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 WindowsTerminal()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableEcho()Disable character echoing.voidenableEcho()Enable character echoing.java.io.InputStreamgetDefaultBindings()java.lang.BooleangetDirectConsole()Whether or not to allow the use of the JNI console interaction.booleangetEcho()Returns true if the terminal will echo all characters type.intgetTerminalHeight()Unsupported; return the default.intgetTerminalWidth()Unsupported; return the default.voidinitializeTerminal()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.booleanisANSISupported()Windows doesn't support ANSI codes by default; disable them.booleanisEchoEnabled()Returns false if character echoing is disabled.booleanisSupported()Returns true if this terminal is capable of initializing the terminal to use jline.intreadCharacter(java.io.InputStream in)Read a single character from the input stream.intreadVirtualKey(java.io.InputStream in)Reads a virtual key from the console.voidsetDirectConsole(java.lang.Boolean directConsole)Whether or not to allow the use of the JNI console interaction.-
Methods inherited from class jline.Terminal
afterReadLine, beforeReadLine, getTerminal, resetTerminal, setupTerminal
-
-
-
-
Field Detail
-
SPECIAL_KEY_INDICATOR
public static final int SPECIAL_KEY_INDICATOR
On windows terminals, this character indicates that a 'special' key has been pressed. This means that a key such as an arrow key, or delete, or home, etc. will be indicated by the next character.- See Also:
- Constant Field Values
-
NUMPAD_KEY_INDICATOR
public static final int NUMPAD_KEY_INDICATOR
On windows terminals, this character indicates that a special key on the number pad has been pressed.- See Also:
- Constant Field Values
-
LEFT_ARROW_KEY
public static final int LEFT_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR, this character indicates an left arrow key press.- See Also:
- Constant Field Values
-
RIGHT_ARROW_KEY
public static final int RIGHT_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an right arrow key press.- See Also:
- Constant Field Values
-
UP_ARROW_KEY
public static final int UP_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an up arrow key press.- See Also:
- Constant Field Values
-
DOWN_ARROW_KEY
public static final int DOWN_ARROW_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an down arrow key press.- See Also:
- Constant Field Values
-
DELETE_KEY
public static final int DELETE_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the delete key was pressed.- See Also:
- Constant Field Values
-
HOME_KEY
public static final int HOME_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the home key was pressed.- See Also:
- Constant Field Values
-
END_KEY
public static final char END_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the end key was pressed.- See Also:
- Constant Field Values
-
PAGE_UP_KEY
public static final char PAGE_UP_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the page up key was pressed.- See Also:
- Constant Field Values
-
PAGE_DOWN_KEY
public static final char PAGE_DOWN_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the page down key was pressed.- See Also:
- Constant Field Values
-
INSERT_KEY
public static final char INSERT_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the insert key was pressed.- See Also:
- Constant Field Values
-
ESCAPE_KEY
public static final char ESCAPE_KEY
When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR, this character indicates that the escape key was pressed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WindowsTerminal
public WindowsTerminal()
-
-
Method Detail
-
readCharacter
public int readCharacter(java.io.InputStream in) throws java.io.IOException
Description copied from class:TerminalRead a single character from the input stream. This might enable a terminal implementation to better handle nuances of the console.- Overrides:
readCharacterin classTerminal- Throws:
java.io.IOException
-
initializeTerminal
public void initializeTerminal() throws java.lang.Exception
Description copied from class:TerminalInitialize 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.- Specified by:
initializeTerminalin classTerminal- Throws:
java.lang.Exception
-
readVirtualKey
public int readVirtualKey(java.io.InputStream in) throws java.io.IOException
Description 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
-
isANSISupported
public boolean isANSISupported()
Windows doesn't support ANSI codes by default; disable them.- Overrides:
isANSISupportedin classTerminal
-
getEcho
public boolean getEcho()
Description copied from class:TerminalReturns true if the terminal will echo all characters type.
-
getTerminalWidth
public int getTerminalWidth()
Unsupported; return the default.- Specified by:
getTerminalWidthin classTerminal- See Also:
Terminal.getTerminalWidth()
-
getTerminalHeight
public int getTerminalHeight()
Unsupported; return the default.- Specified by:
getTerminalHeightin classTerminal- See Also:
Terminal.getTerminalHeight()
-
setDirectConsole
public void setDirectConsole(java.lang.Boolean directConsole)
Whether or not to allow the use of the JNI console interaction.
-
getDirectConsole
public java.lang.Boolean getDirectConsole()
Whether or not to allow the use of the JNI console interaction.
-
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
-
getDefaultBindings
public java.io.InputStream getDefaultBindings()
- Overrides:
getDefaultBindingsin classTerminal
-
-