Package org.beryx.textio.jline
Class JLineTextTerminal
- java.lang.Object
-
- org.beryx.textio.AbstractTextTerminal<JLineTextTerminal>
-
- org.beryx.textio.jline.JLineTextTerminal
-
- All Implemented Interfaces:
TextTerminal<JLineTextTerminal>
public class JLineTextTerminal extends AbstractTextTerminal<JLineTextTerminal>
A JLine-basedTextTerminal
.
-
-
Field Summary
-
Fields inherited from class org.beryx.textio.AbstractTextTerminal
DEFAULT_USER_INTERRUPT_KEY, SYSPROP_PROPERTIES_FILE_LOCATION
-
-
Constructor Summary
Constructors Constructor Description JLineTextTerminal()
JLineTextTerminal(jline.console.ConsoleReader reader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.static jline.console.ConsoleReader
createReader()
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.java.lang.String
getAnsiBackgroundColor(java.lang.String colorName)
java.lang.String
getAnsiColor(java.lang.String colorName)
java.lang.String
getAnsiPrefix(org.beryx.textio.jline.JLineTextTerminal.StyleData styleData)
java.util.Optional<java.lang.String>
getColorCode(java.lang.String colorName)
static java.lang.String
getKeySequence(java.lang.String keyStroke)
jline.console.ConsoleReader
getReader()
static int
getStandardColorCode(java.lang.String colorName)
boolean
moveToLineStart()
Moves the cursor to the start of the current line of text in order to allow overwriting the current line.void
printAnsi(java.lang.String message)
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 textboolean
registerHandler(java.lang.String keyStroke, java.util.function.Function<JLineTextTerminal,ReadHandlerData> handler)
Associates a key combination to a handler.boolean
registerUserInterruptHandler(java.util.function.Consumer<JLineTextTerminal> handler, boolean abortRead)
Registers a handler that will be called in response to a user interrupt.boolean
resetLine()
Clears the current line of text.void
setAnsiColorMode(java.lang.String mode)
void
setInputBackgroundColor(java.lang.String colorName)
void
setInputBold(boolean bold)
void
setInputColor(java.lang.String colorName)
void
setInputItalic(boolean italic)
void
setInputUnderline(boolean underline)
void
setPromptBackgroundColor(java.lang.String colorName)
void
setPromptBold(boolean bold)
void
setPromptColor(java.lang.String colorName)
void
setPromptItalic(boolean italic)
void
setPromptUnderline(boolean underline)
-
Methods inherited from class org.beryx.textio.AbstractTextTerminal
addDefaultProperty, getDefaultProperties, getProperties, getPropertiesPrefixes, getPropertiesReader, init, initProperties, initProperties, initProperties
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.beryx.textio.TextTerminal
applyWithPropertiesConfigurator, dispose, executeWithPropertiesConfigurator, executeWithPropertiesPrefix, print, print, printf, printf, println, println, rawPrint, resetToBookmark, setBookmark
-
-
-
-
Method Detail
-
getStandardColorCode
public static int getStandardColorCode(java.lang.String colorName)
-
getColorCode
public java.util.Optional<java.lang.String> getColorCode(java.lang.String colorName)
-
getAnsiColor
public java.lang.String getAnsiColor(java.lang.String colorName)
-
getAnsiBackgroundColor
public java.lang.String getAnsiBackgroundColor(java.lang.String colorName)
-
createReader
public static jline.console.ConsoleReader createReader()
-
read
public java.lang.String read(boolean masking)
Description copied from interface:TextTerminal
Reads a line of text- Parameters:
masking
- true, if the input should be masked (for example to enter a password)- Returns:
- the entered text
-
rawPrint
public void rawPrint(java.lang.String message)
Description copied from interface:TextTerminal
Prints the message in its raw form. This method expects a single line of text. The behavior is undefined if the string contains line separators.
-
printAnsi
public void printAnsi(java.lang.String message)
-
getAnsiPrefix
public java.lang.String getAnsiPrefix(org.beryx.textio.jline.JLineTextTerminal.StyleData styleData)
-
println
public void println()
Description copied from interface:TextTerminal
Terminates the current line by writing the line separator string.
-
resetLine
public boolean resetLine()
Description copied from interface:TextTerminal
Clears the current line of text. Since not all terminals support this feature, the default implementation callsTextTerminal.println()
and returns false.- Returns:
- true, if the terminal supports this feature and the current line has been successfully cleared.
-
moveToLineStart
public boolean moveToLineStart()
Description copied from interface:TextTerminal
Moves the cursor to the start of the current line of text in order to allow overwriting the current line. Since not all terminals support this feature, the default implementation callsTextTerminal.println()
and returns false.- Returns:
- true, if the terminal supports this feature and the cursor has been moved to the start of the current line.
-
registerUserInterruptHandler
public boolean registerUserInterruptHandler(java.util.function.Consumer<JLineTextTerminal> handler, boolean abortRead)
Description copied from interface:TextTerminal
Registers a handler that will be called in response to a user interrupt. The event that triggers a user interrupt is usually Ctrl+C, but in general it is terminal specific. For example, a Swing based terminal may send a user interrupt when the X close button of its window is hit. Since not all terminals support this feature, the default implementation just returns false.- Parameters:
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.- Returns:
- true, if the terminal supports this feature and the handler has been registered; false, otherwise.
-
registerHandler
public boolean registerHandler(java.lang.String keyStroke, java.util.function.Function<JLineTextTerminal,ReadHandlerData> handler)
Description copied from interface:TextTerminal
Associates a key combination to a handler. Since not all terminals support this feature, the default implementation just returns false.- Parameters:
keyStroke
- the key combination associated with the handler. It should have the same format as the argument ofKeyStroke.getKeyStroke(String)
.handler
- the action to be performed when thekeyStroke
is detected during a read operation.- Returns:
- true, if the terminal supports this feature and the handler has been associated with the given key combination; false, otherwise.
-
dispose
public void dispose(java.lang.String resultData)
Description copied from interface:TextTerminal
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. The terminal should be able to rebuild the released resources when a print or read method is subsequently called. The default implementation does nothing.- Parameters:
resultData
- stringified information about the outcome of the input/output session; may be null,
-
abort
public void abort()
Description copied from interface:TextTerminal
This method is typically called when a text-based input/output session has been aborted by the user or when a severe error occurred. The default implementation does nothing.
-
getReader
public jline.console.ConsoleReader getReader()
-
setPromptColor
public void setPromptColor(java.lang.String colorName)
-
setPromptBackgroundColor
public void setPromptBackgroundColor(java.lang.String colorName)
-
setPromptBold
public void setPromptBold(boolean bold)
-
setPromptItalic
public void setPromptItalic(boolean italic)
-
setPromptUnderline
public void setPromptUnderline(boolean underline)
-
setInputColor
public void setInputColor(java.lang.String colorName)
-
setInputBackgroundColor
public void setInputBackgroundColor(java.lang.String colorName)
-
setInputBold
public void setInputBold(boolean bold)
-
setInputItalic
public void setInputItalic(boolean italic)
-
setInputUnderline
public void setInputUnderline(boolean underline)
-
setAnsiColorMode
public void setAnsiColorMode(java.lang.String mode)
-
getKeySequence
public static java.lang.String getKeySequence(java.lang.String keyStroke)
-
-