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
 
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
 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 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.
 
Methods inherited from class jline.Terminal
getTerminal, setupTerminal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WindowsTerminal

public WindowsTerminal()
Method Detail

readCharacter

public int readCharacter(InputStream in)
                  throws 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:
IOException

initializeTerminal

public void initializeTerminal()
                        throws 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:
Exception

readVirtualKey

public int readVirtualKey(InputStream in)
                   throws 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:
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()

setDirectConsole

public void setDirectConsole(Boolean directConsole)
Whether or not to allow the use of the JNI console interaction.


getDirectConsole

public Boolean getDirectConsole()
Whether or not to allow the use of the JNI console interaction.



Released under the terms of the BSD license