public interface TextTerminal<T extends TextTerminal<T>>
Modifier and Type | Method and Description |
---|---|
default 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.
|
default <R> R |
applyWithPropertiesConfigurator(java.util.function.Consumer<TerminalProperties<?>> propertiesConfigurator,
java.util.function.Function<TextTerminal<T>,R> action)
Executes an action that returns a result, while temporarily modifying the terminal properties.
|
default void |
dispose()
Convenience method for disposing the terminal without providing information about the outcome of the input/output session.
|
default 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.
|
default void |
executeWithPropertiesConfigurator(java.util.function.Consumer<TerminalProperties<?>> propertiesConfigurator,
java.util.function.Consumer<TextTerminal<T>> action)
Executes an action while temporarily modifying the terminal properties.
|
TerminalProperties<T> |
getProperties() |
default void |
init()
This method is typically called after the terminal has been created.
|
default boolean |
moveToLineStart()
Moves the cursor to the start of the current line of text in order to allow overwriting the current line.
|
default void |
print(java.util.List<java.lang.String> messages)
Prints each message in the list, inserting the line separator string between messages.
|
default void |
print(java.lang.String message)
Prints a message that possibly contains line separators.
|
default void |
printf(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
Prints a formatted string using the specified locale, format string and arguments.
|
default void |
printf(java.lang.String format,
java.lang.Object... args)
Prints a formatted string using the default locale and the specified format string and arguments.
|
void |
println()
Terminates the current line by writing the line separator string.
|
default void |
println(java.util.List<java.lang.String> messages)
Prints each message in the list, inserting the line separator string between messages.
|
default void |
println(java.lang.String message)
Prints a message that possibly contains line separators and subsequently prints a line separator.
|
default void |
rawPrint(java.util.List<java.lang.String> messages)
Prints each message in the list in its raw form, inserting the line separator string between messages.
|
void |
rawPrint(java.lang.String message)
Prints the message in its raw form.
|
java.lang.String |
read(boolean masking)
Reads a line of text
|
default boolean |
registerHandler(java.lang.String keyStroke,
java.util.function.Function<T,ReadHandlerData> handler)
Associates a key combination to a handler.
|
default boolean |
registerUserInterruptHandler(java.util.function.Consumer<T> handler,
boolean abortRead)
Registers a handler that will be called in response to a user interrupt.
|
default boolean |
resetLine()
Clears the current line of text.
|
default boolean |
resetToBookmark(java.lang.String bookmark)
Clears the text after the given bookmark.
|
default boolean |
setBookmark(java.lang.String bookmark)
Sets a bookmark with the given name at the current position.
|
java.lang.String read(boolean masking)
masking
- true, if the input should be masked (for example to enter a password)void rawPrint(java.lang.String message)
void println()
TerminalProperties<T> getProperties()
TerminalProperties
of this text terminal.default boolean registerUserInterruptHandler(java.util.function.Consumer<T> handler, boolean abortRead)
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.default boolean registerHandler(java.lang.String keyStroke, java.util.function.Function<T,ReadHandlerData> handler)
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.default void init()
default void dispose(java.lang.String resultData)
resultData
- stringified information about the outcome of the input/output session; may be null,default void dispose()
dispose(String)
with a null argument.default void abort()
default boolean resetLine()
println()
and returns false.default boolean moveToLineStart()
println()
and returns false.default boolean setBookmark(java.lang.String bookmark)
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.default boolean resetToBookmark(java.lang.String bookmark)
resetToBookmark(String)
in order to clear the text after this bookmark.
Since not all terminals support this feature, the default implementation calls println()
and returns false.default void rawPrint(java.util.List<java.lang.String> messages)
default void print(java.lang.String message)
default void println(java.lang.String message)
default void print(java.util.List<java.lang.String> messages)
default void println(java.util.List<java.lang.String> messages)
default void printf(java.lang.String format, java.lang.Object... args)
format
- A format string as described in Formatter
.args
- Arguments referenced by the format specifiers in the format string.default void printf(java.util.Locale l, java.lang.String format, java.lang.Object... args)
l
- The locale to apply during formatting. If l
is null
then no localization is applied.format
- A format string as described in Formatter
.args
- Arguments referenced by the format specifiers in the format string.default void executeWithPropertiesConfigurator(java.util.function.Consumer<TerminalProperties<?>> propertiesConfigurator, java.util.function.Consumer<TextTerminal<T>> action)
propertiesConfigurator
- the task that is in charge of modifying the TerminalProperties.
The configurator will be applied to the terminal properties before starting the action and
the properties will be reverted to their previous values at the end of the action.action
- the action to be executed, usually consisting of a series of TextTerminal-related operations.default <R> R applyWithPropertiesConfigurator(java.util.function.Consumer<TerminalProperties<?>> propertiesConfigurator, java.util.function.Function<TextTerminal<T>,R> action)
propertiesConfigurator
- the task that is in charge of modifying the TerminalProperties.
The configurator will be applied to the terminal properties before starting the action and
the properties will be reverted to their previous values at the end of the action.action
- the action to be performed on the TextTerminal in order to obtain a result.
Usually, the result is the return value of a read(boolean)
operation.