com.mindbright.terminal
public final class LineReaderTerminal extends java.lang.Object implements TerminalInputListener
TerminalWindow
Modifier and Type | Class and Description |
---|---|
static class |
LineReaderTerminal.ExternalMessageException
Represents an external message which came in while the
LineReaderTerminal was waiting for input.
|
Constructor and Description |
---|
LineReaderTerminal(TerminalWindow terminal)
Creates a new instance and attaches to the given terminal.
|
Modifier and Type | Method and Description |
---|---|
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 |
sendBytesDirect(byte[] b)
Send some bytes directly to the host.
|
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
|
public LineReaderTerminal(TerminalWindow terminal)
terminal
- the terminal window to work onpublic void detach()
public void print(java.lang.String str)
str
- text to printpublic void println(java.lang.String str)
str
- text to printpublic void breakPromptLine(java.lang.String msg)
promptLine
to throw an
ExternalMessageException
with the given message.msg
- message for exceptionpublic java.lang.String readLine(java.lang.String defaultVal)
defaultVal
- default value which is returned if the user
did not enter anything.public java.lang.String promptLine(java.lang.String prompt, java.lang.String defaultVal, boolean echoStar) throws LineReaderTerminal.ExternalMessageException
prompt
- lime of text to show at the start of the linedefaultVal
- 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.LineReaderTerminal.ExternalMessageException
- this is thrown if somebody
called breakPromptLine
while this call was waiting
for the user.public boolean ctrlCPressed()
public void typedChar(char c)
TerminalInputListener
typedChar
in interface TerminalInputListener
c
- typed characterpublic void typedChar(byte[] b)
TerminalInputListener
typedChar
in interface TerminalInputListener
b
- byte code representation fo the character encoded in
the current encoding.public void sendBytes(byte[] b)
TerminalInputListener
sendBytes
in interface TerminalInputListener
b
- array of bytes representing characters to inputpublic void sendBytesDirect(byte[] b)
TerminalInputListener
sendBytesDirect
in interface TerminalInputListener
b
- array of bytes representing characters to sendpublic void signalWindowChanged(int rows, int cols, int vpixels, int hpixels)
TerminalInputListener
signalWindowChanged
in interface TerminalInputListener
rows
- new number of rowscols
- new number of columnsvpixels
- new number of vertical pixelshpixels
- new number of horizontal pixelspublic void signalTermTypeChanged(java.lang.String newTermType)
TerminalInputListener
signalTermTypeChanged
in interface TerminalInputListener
newTermType
- new terminal type to emulatepublic void sendBreak()
TerminalInputListener
sendBreak
in interface TerminalInputListener