jline
Class WindowsTerminal

java.lang.Object
  extended byjline.Terminal
      extended byjline.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 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.

Author:
Marc Prud'hommeaux

Field Summary
private  java.lang.Boolean directConsole
           
private static int ENABLE_ECHO_INPUT
          Characters read by the ReadFile or ReadConsole function are written to the active screen buffer as they are read.
private static int ENABLE_LINE_INPUT
          The ReadFile or ReadConsole function returns only when a carriage return character is read.
private static int ENABLE_MOUSE_INPUT
          If the mouse pointer is within the borders of the console window and the window has the keyboard focus, mouse events generated by mouse movement and button presses are placed in the input buffer.
private static int ENABLE_PROCESSED_INPUT
          CTRL+C is processed by the system and is not placed in the input buffer.
private static int ENABLE_PROCESSED_OUTPUT
          When enabled, text entered in a console window will be inserted at the current cursor location and all text following that location will not be overwritten.
private static int ENABLE_WINDOW_INPUT
          User interactions that change the size of the console screen buffer are reported in the console's input buffee.
private static int ENABLE_WRAP_AT_EOL_OUTPUT
          This flag enables the user to use the mouse to select and edit text.
 
Fields inherited from class jline.Terminal
 
Fields inherited from interface jline.ConsoleOperations
ADD, BACKSPACE, CHANGE_CASE, CHANGE_META, CLEAR_SCREEN, COMPLETE, CR, CTRL_A, CTRL_B, CTRL_C, CTRL_D, CTRL_E, CTRL_F, CTRL_N, CTRL_P, DELETE_META, DELETE_NEXT_CHAR, DELETE_PREV_CHAR, DELETE_PREV_WORD, 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, SUBSTITUTE_CHAR, SUBSTITUTE_LINE, TO_END_WORD, TO_NEXT_CHAR, TO_PREV_CHAR, UNDO, UNKNOWN
 
Constructor Summary
WindowsTerminal()
           
 
Method Summary
private  void consumeException(java.lang.Throwable e)
          No-op for exceptions we want to silently consume.
private  int getConsoleMode()
           
 java.lang.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.
private  int getWindowsTerminalHeight()
           
private  int getWindowsTerminalWidth()
           
 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 isSupported()
          Returns true if this terminal is capable of initializing the terminal to use jline.
private  void loadLibrary(java.lang.String name)
           
private  int readByte()
           
 int readCharacter(java.io.InputStream in)
          Read a single character from the input stream.
 int readVirtualKey(java.io.InputStream in)
          Reads a virtual key from the console.
private  void setConsoleMode(int mode)
           
 void setDirectConsole(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, setupTerminal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE_LINE_INPUT

private static final int ENABLE_LINE_INPUT
The ReadFile or ReadConsole function returns only when a carriage return character is read. If this mode is disable, the functions return when one or more characters are available.

See Also:
Constant Field Values

ENABLE_ECHO_INPUT

private static final int ENABLE_ECHO_INPUT
Characters read by the ReadFile or ReadConsole function are written to the active screen buffer as they are read. This mode can be used only if the ENABLE_LINE_INPUT mode is also enabled.

See Also:
Constant Field Values

ENABLE_PROCESSED_INPUT

private static final int ENABLE_PROCESSED_INPUT
CTRL+C is processed by the system and is not placed in the input buffer. If the input buffer is being read by ReadFile or ReadConsole, other control keys are processed by the system and are not returned in the ReadFile or ReadConsole buffer. If the ENABLE_LINE_INPUT mode is also enabled, backspace, carriage return, and linefeed characters are handled by the system.

See Also:
Constant Field Values

ENABLE_WINDOW_INPUT

private static final int ENABLE_WINDOW_INPUT
User interactions that change the size of the console screen buffer are reported in the console's input buffee. Information about these events can be read from the input buffer by applications using theReadConsoleInput function, but not by those using ReadFile orReadConsole.

See Also:
Constant Field Values

ENABLE_MOUSE_INPUT

private static final int ENABLE_MOUSE_INPUT
If the mouse pointer is within the borders of the console window and the window has the keyboard focus, mouse events generated by mouse movement and button presses are placed in the input buffer. These events are discarded by ReadFile or ReadConsole, even when this mode is enabled.

See Also:
Constant Field Values

ENABLE_PROCESSED_OUTPUT

private static final int ENABLE_PROCESSED_OUTPUT
When enabled, text entered in a console window will be inserted at the current cursor location and all text following that location will not be overwritten. When disabled, all following text will be overwritten. An OR operation must be performed with this flag and the ENABLE_EXTENDED_FLAGS flag to enable this functionality.

See Also:
Constant Field Values

ENABLE_WRAP_AT_EOL_OUTPUT

private static final int ENABLE_WRAP_AT_EOL_OUTPUT
This flag enables the user to use the mouse to select and edit text. To enable this option, use the OR to combine this flag with ENABLE_EXTENDED_FLAGS.

See Also:
Constant Field Values

directConsole

private java.lang.Boolean directConsole
Constructor Detail

WindowsTerminal

public WindowsTerminal()
Method Detail

getConsoleMode

private int getConsoleMode()

setConsoleMode

private void setConsoleMode(int mode)

readByte

private int readByte()

getWindowsTerminalWidth

private int getWindowsTerminalWidth()

getWindowsTerminalHeight

private int getWindowsTerminalHeight()

readCharacter

public int readCharacter(java.io.InputStream in)
                  throws java.io.IOException
Description copied from class: Terminal
Read a single character from the input stream. This might enable a terminal implementation to better handle nuances of the console.

Overrides:
readCharacter in class Terminal
Throws:
java.io.IOException

initializeTerminal

public void initializeTerminal()
                        throws java.lang.Exception
Description copied from class: Terminal
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.

Specified by:
initializeTerminal in class Terminal
Throws:
java.lang.Exception

loadLibrary

private void loadLibrary(java.lang.String name)
                  throws java.io.IOException
Throws:
java.io.IOException

readVirtualKey

public int readVirtualKey(java.io.InputStream in)
                   throws java.io.IOException
Description copied from class: Terminal
Reads 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:
readVirtualKey in class Terminal
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: Terminal
Returns true if this terminal is capable of initializing the terminal to use jline.

Specified by:
isSupported in class Terminal

isANSISupported

public boolean isANSISupported()
Windows doesn't support ANSI codes by default; disable them.

Overrides:
isANSISupported in class Terminal

getEcho

public boolean getEcho()
Description copied from class: Terminal
Returns true if the terminal will echo all characters type.

Specified by:
getEcho in class Terminal

getTerminalWidth

public int getTerminalWidth()
Unsupported; return the default.

Specified by:
getTerminalWidth in class Terminal
See Also:
Terminal.getTerminalWidth()

getTerminalHeight

public int getTerminalHeight()
Unsupported; return the default.

Specified by:
getTerminalHeight in class Terminal
See Also:
Terminal.getTerminalHeight()

consumeException

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


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.