Package net.morimekta.console.terminal
Class InputLine
- java.lang.Object
-
- net.morimekta.console.terminal.InputLine
-
public class InputLine extends java.lang.Object
Class that handled reading a line from terminal input with character and line validators, and optional tab completion.When writing input into an app it is problematic if the app crashes or exits every time you makes invalid input. This can be solved with the
InputLine.CharValidator
andInputLine.LineValidator
interfaces. TheCharValidator
validates that any single char input is valid, and will block if not. TheLineValidator
is triggered when the user finishes the input and checks if the line is valid as a whole, and blocks completion if not.In addition a
InputLine.TabCompletion
interface may be provided that can complete input based on the current content before the cursor. If thecomplete()
method returns a string, it will replace what was before.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
InputLine.CharValidator
Character validator interface.static interface
InputLine.LineValidator
Line validator interface.static interface
InputLine.TabCompletion
Tab completion interface.
-
Constructor Summary
Constructors Constructor Description InputLine(Terminal terminal, java.lang.String message)
Constructor for simple line-input.InputLine(Terminal terminal, java.lang.String message, InputLine.CharValidator charValidator, InputLine.LineValidator lineValidator, InputLine.TabCompletion tabCompletion)
Constructor for complete line-input.InputLine(Terminal terminal, java.lang.String message, InputLine.CharValidator charValidator, InputLine.LineValidator lineValidator, InputLine.TabCompletion tabCompletion, java.util.regex.Pattern delimiterPattern)
Constructor for complete line-input.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
readLine()
Read line from terminal.java.lang.String
readLine(java.lang.String initial)
Read line from terminal.
-
-
-
Constructor Detail
-
InputLine
public InputLine(Terminal terminal, java.lang.String message)
Constructor for simple line-input.- Parameters:
terminal
- Terminal to use.message
- Message to print.
-
InputLine
public InputLine(Terminal terminal, java.lang.String message, InputLine.CharValidator charValidator, InputLine.LineValidator lineValidator, InputLine.TabCompletion tabCompletion)
Constructor for complete line-input.- Parameters:
terminal
- Terminal to use.message
- Message to print.charValidator
- The character validcator or null.lineValidator
- The line validator or null.tabCompletion
- The tab expander or null.
-
InputLine
public InputLine(Terminal terminal, java.lang.String message, InputLine.CharValidator charValidator, InputLine.LineValidator lineValidator, InputLine.TabCompletion tabCompletion, java.util.regex.Pattern delimiterPattern)
Constructor for complete line-input.- Parameters:
terminal
- Terminal to use.message
- Message to print.charValidator
- The character validcator or null.lineValidator
- The line validator or null.tabCompletion
- The tab expander or null.delimiterPattern
- Pattern matching a character that delimit 'words' that are skipped or deleted with [ctrl-left], [ctrl-right], [alt-w] and [alt-d].
-
-