Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.mindbright.terminal
Class LineReaderTerminal

    java.lang.Object
      com.mindbright.terminal.LineReaderTerminal

All Implemented Interfaces:
  TerminalInputListener

public final class LineReaderTerminal
extends java.lang.Object
implements TerminalInputListener

This class handles line based interaction with the user over a terminal window. That is the class contains methods for printing lines and read input from the user.

See Also:
  `TerminalWindow`

Nested Class Summary
`static class` | `LineReaderTerminal.ExternalMessageException` Represents an external message which came in while the LineReaderTerminal was waiting for input.

Constructor Summary
`LineReaderTerminal(TerminalWindow terminal)` Creates a new instance and attaches to the given terminal.

Method Summary
`void` | `breakPromptLine(java.lang.String msg)` Abort waiting for user input.
`boolean` | `ctrlCPressed()` Check if the user has pressed control-C since the last time this function was called.
`void` | `detach()` Detach from the terminal window
`void` | `print(java.lang.String str)` Print a string on the terminal
`void` | `println(java.lang.String str)` Print a string on the terminal followind by a newline
`java.lang.String` | `promptLine(java.lang.String prompt, java.lang.String defaultVal, boolean echoStar)` Print a prompt and wait for user input.
`java.lang.String` | `readLine(java.lang.String defaultVal)` Read a line of input from the user.
`void` | `sendBreak()` Called when the user sends a break to the terminal
`void` | `sendBytes(byte[] b)` May be called when the user pastes data.
`void` | `signalTermTypeChanged(java.lang.String newTermType)` Called when the terminal type has changed.
`void` | `signalWindowChanged(int rows, int cols, int vpixels, int hpixels)` Called when the size of the terminal window has changed.
`void` | `typedChar(byte[] b)` Called when the user types a character
`void` | `typedChar(char c)` Called when the user types a character

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LineReaderTerminal

    public LineReaderTerminal(TerminalWindow terminal)

  Creates a new instance and attaches to the given terminal.

Parameters:
  `terminal` - the terminal window to work on

Method Detail

### detach

    public void detach()

  Detach from the terminal window

### print

    public void print(java.lang.String str)

  Print a string on the terminal

  Parameters:
    `str` - text to print

### println

    public void println(java.lang.String str)

  Print a string on the terminal followind by a newline

  Parameters:
    `str` - text to print

### breakPromptLine

    public void breakPromptLine(java.lang.String msg)

  Abort waiting for user input. This causes any outstanding call to `promptLine` to throw an `ExternalMessageException` with the given message.

  Parameters:
    `msg` - message for exception

### readLine

    public java.lang.String readLine(java.lang.String defaultVal)

  Read a line of input from the user. It is also possible to speciy a default value which is returned if the user just presses return without entering anything.

  Parameters:
    `defaultVal` - default value which is returned if the user did not enter anything.
  Returns:
    the entered text or defaultVal if no text was entered

### promptLine

    public java.lang.String promptLine(java.lang.String prompt,
                                       java.lang.String defaultVal,
                                       boolean echoStar)
                                throws LineReaderTerminal.ExternalMessageException

  Print a prompt and wait for user input. It is possibke to give a default value and also to make the terminal echo '*' instead of the entered text (for password entry)

  Parameters:
    `prompt` - lime of text to show at the start of the line
    `defaultVal` - default value which is returned if the user just presses return without entering any text.
    `echoStar` - if true then the terminal echoes a '*; instead of the typed character.
  Returns:
    the entered text or defaultVal if no text was entered
  Throws:
    `LineReaderTerminal.ExternalMessageException` - this is thrown if somebody called `breakPromptLine` while this call was waiting for the user.

### ctrlCPressed

    public boolean ctrlCPressed()

  Check if the user has pressed control-C since the last time this function was called.

  Returns:
    true if control-C has been pressed

### typedChar

    public void typedChar(char c)

  Description copied from interface: `TerminalInputListener`
  Called when the user types a character

  Specified by:
    `typedChar` in interface `TerminalInputListener`
  Parameters:
    `c` - typed character

### typedChar

    public void typedChar(byte[] b)

  Description copied from interface: `TerminalInputListener`
  Called when the user types a character

  Specified by:
    `typedChar` in interface `TerminalInputListener`
  Parameters:
    `b` - byte code representation fo the character encoded in the current encoding.

### sendBytes

    public void sendBytes(byte[] b)

  Description copied from interface: `TerminalInputListener`
  May be called when the user pastes data. It may also be called by some external entity whishing to simulate multiple key presses.

  Specified by:
    `sendBytes` in interface `TerminalInputListener`
  Parameters:
    `b` - array of bytes representing characters to input

### signalWindowChanged

    public void signalWindowChanged(int rows,
                                    int cols,
                                    int vpixels,
                                    int hpixels)

  Description copied from interface: `TerminalInputListener`
  Called when the size of the terminal window has changed.

  Specified by:
    `signalWindowChanged` in interface `TerminalInputListener`
  Parameters:
    `rows` - new number of rows
    `cols` - new number of columns
    `vpixels` - new number of vertical pixels
    `hpixels` - new number of horizontal pixels

### signalTermTypeChanged

    public void signalTermTypeChanged(java.lang.String newTermType)

  Description copied from interface: `TerminalInputListener`
  Called when the terminal type has changed. That is when the user has changed which terminal type this terminal window should emulate.

  Specified by:
    `signalTermTypeChanged` in interface `TerminalInputListener`
  Parameters:
    `newTermType` - new terminal type to emulate

### sendBreak

    public void sendBreak()

  Description copied from interface: `TerminalInputListener`
  Called when the user sends a break to the terminal

  Specified by:
    `sendBreak` in interface `TerminalInputListener`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD