public class WebTextTerminal extends AbstractTextTerminal<WebTextTerminal> implements DataApi
TextTerminal that allows accessing the application via a browser.
It works only in conjunction with a web server supporting the DataApi (such as SparkDataServer)
and a web component that accesses this API (typically via textterm.js).| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_TIMEOUT_DATA_CLEARED |
static long |
DEFAULT_TIMEOUT_HAS_ACTION |
static long |
DEFAULT_TIMEOUT_NOT_EMPTY |
DEFAULT_USER_INTERRUPT_KEY, SYSPROP_PROPERTIES_FILE_LOCATION| Constructor and Description |
|---|
WebTextTerminal() |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
This method is typically called when a text-based input/output session has been aborted by the user or when a severe error occurred.
|
void |
addSetting(java.lang.String key,
java.lang.Object value) |
void |
addSettings(TextTerminalData.KeyValue... keyValues) |
WebTextTerminal |
createCopy() |
void |
dispose(java.lang.String resultData)
This method is typically called at the end of a text-based input/output session in order to allow the terminal to release its screen resources.
|
TextTerminalData |
getTextTerminalData()
This method is called by the web component while polling for data
|
boolean |
moveToLineStart()
Moves the cursor to the start of the current line of text in order to allow overwriting the current line.
|
void |
postHandlerCall(java.lang.String handlerId,
java.lang.String partialInput)
This method is called by the web component in response to a handler call (triggered by typing its associated key combination).
|
void |
postUserInput(java.lang.String newInput)
This method is called by the web component to post the user input
|
void |
postUserInput(java.lang.String newInput,
boolean userInterrupt,
java.lang.String handlerId) |
void |
postUserInterrupt(java.lang.String partialInput)
This method is called by the web component in response to a user interrupt (typically triggered by typing Ctrl+Q).
|
void |
println()
Terminates the current line by writing the line separator string.
|
void |
rawPrint(java.lang.String message)
Prints the message in its raw form.
|
java.lang.String |
read(boolean masking)
Reads a line of text
|
boolean |
registerHandler(java.lang.String keyStroke,
java.util.function.Function<WebTextTerminal,ReadHandlerData> handler)
Associates a key combination to a handler.
|
boolean |
registerUserInterruptHandler(java.util.function.Consumer<WebTextTerminal> handler,
boolean abortRead)
Registers a handler that will be called in response to a user interrupt.
|
boolean |
resetLine()
Clears the current line of text.
|
boolean |
resetToBookmark(java.lang.String bookmark)
Clears the text after the given bookmark.
|
protected void |
setAction(TextTerminalData.Action action) |
protected void |
setAction(TextTerminalData.Action action,
java.lang.String actionData) |
boolean |
setBookmark(java.lang.String bookmark)
Sets a bookmark with the given name at the current position.
|
void |
setOnAbort(java.lang.Runnable onAbort) |
void |
setOnDispose(java.lang.Runnable onDispose) |
void |
setTimeoutDataCleared(long timeoutDataCleared) |
void |
setTimeoutHasAction(long timeoutHasAction) |
void |
setTimeoutNotEmpty(long timeoutNotEmpty) |
void |
setUserInterruptKey(int code,
boolean ctrl,
boolean shift,
boolean alt) |
void |
setUserInterruptKey(java.lang.String keyStroke) |
addDefaultProperty, getDefaultProperties, getProperties, getPropertiesPrefixes, getPropertiesReader, init, initProperties, initProperties, initPropertiesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitapplyWithPropertiesConfigurator, dispose, executeWithPropertiesConfigurator, executeWithPropertiesPrefix, print, print, printf, printf, println, println, rawPrintpublic static final long DEFAULT_TIMEOUT_NOT_EMPTY
public static final long DEFAULT_TIMEOUT_HAS_ACTION
public static final long DEFAULT_TIMEOUT_DATA_CLEARED
public void setTimeoutNotEmpty(long timeoutNotEmpty)
public void setTimeoutHasAction(long timeoutHasAction)
public void setTimeoutDataCleared(long timeoutDataCleared)
public WebTextTerminal createCopy()
public void dispose(java.lang.String resultData)
TextTerminaldispose in interface TextTerminal<WebTextTerminal>resultData - stringified information about the outcome of the input/output session; may be null,public void abort()
TextTerminalabort in interface TextTerminal<WebTextTerminal>public boolean resetLine()
TextTerminalTextTerminal.println() and returns false.resetLine in interface TextTerminal<WebTextTerminal>public boolean moveToLineStart()
TextTerminalTextTerminal.println() and returns false.moveToLineStart in interface TextTerminal<WebTextTerminal>public boolean setBookmark(java.lang.String bookmark)
TextTerminalTextTerminal.resetToBookmark(String) in order to clear the text after this bookmark.
If a bookmark with this name already exists, it will be overwritten.
Since not all terminals support this feature, the default implementation does nothing and returns false.setBookmark in interface TextTerminal<WebTextTerminal>public boolean resetToBookmark(java.lang.String bookmark)
TextTerminalTextTerminal.resetToBookmark(String) in order to clear the text after this bookmark.
Since not all terminals support this feature, the default implementation calls TextTerminal.println() and returns false.resetToBookmark in interface TextTerminal<WebTextTerminal>public void setOnDispose(java.lang.Runnable onDispose)
public void setOnAbort(java.lang.Runnable onAbort)
public java.lang.String read(boolean masking)
TextTerminalread in interface TextTerminal<WebTextTerminal>masking - true, if the input should be masked (for example to enter a password)protected void setAction(TextTerminalData.Action action)
protected void setAction(TextTerminalData.Action action, java.lang.String actionData)
public void rawPrint(java.lang.String message)
TextTerminalrawPrint in interface TextTerminal<WebTextTerminal>public void println()
TextTerminalprintln in interface TextTerminal<WebTextTerminal>public boolean registerUserInterruptHandler(java.util.function.Consumer<WebTextTerminal> handler, boolean abortRead)
TextTerminalregisterUserInterruptHandler in interface TextTerminal<WebTextTerminal>handler - the action to be performed in response to a user interrupt.abortRead - true, if the current read operation should be aborted on user interrupt.public boolean registerHandler(java.lang.String keyStroke,
java.util.function.Function<WebTextTerminal,ReadHandlerData> handler)
TextTerminalregisterHandler in interface TextTerminal<WebTextTerminal>keyStroke - the key combination associated with the handler.
It should have the same format as the argument of KeyStroke.getKeyStroke(String).handler - the action to be performed when the keyStroke is detected during a read operation.public TextTerminalData getTextTerminalData()
DataApigetTextTerminalData in interface DataApipublic void postUserInput(java.lang.String newInput,
boolean userInterrupt,
java.lang.String handlerId)
public void postUserInput(java.lang.String newInput)
DataApipostUserInput in interface DataApipublic void postUserInterrupt(java.lang.String partialInput)
DataApipostUserInterrupt in interface DataApipartialInput - the partially entered input when the user interrupt occurred.public void postHandlerCall(java.lang.String handlerId,
java.lang.String partialInput)
DataApipostHandlerCall in interface DataApihandlerId - the id of the handler to be called.partialInput - the partially entered input when the hander call occurred.public void setUserInterruptKey(java.lang.String keyStroke)
public void addSetting(java.lang.String key,
java.lang.Object value)
public void addSettings(TextTerminalData.KeyValue... keyValues)
public void setUserInterruptKey(int code,
boolean ctrl,
boolean shift,
boolean alt)