Package com.calebleavell.jatui.modules
Class TextInputModule
java.lang.Object
com.calebleavell.jatui.modules.TUIModule
com.calebleavell.jatui.modules.TextInputModule
Handles collection of text for the application. Generally this means collecting user input from the console,
but
A TextInputModule can't do much unless it belongs to an
TUIModule.Builder.scanner(Scanner) can be used to collect input from other places as well.
A TextInputModule can't do much unless it belongs to an
ApplicationModule.
If it is tied to one, whatever input is collected is updated in the app's inputMap and can
be accessed via ApplicationModule.getInput(String).-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.calebleavell.jatui.modules.TUIModule
TUIModule.Property -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA basic default error message if input is determined to be invalid via an InputHandler or something else.Fields inherited from class com.calebleavell.jatui.modules.TUIModule
DEFAULT_SCANNER, logger, restart, UNNAMED_ERROR -
Constructor Summary
ConstructorsConstructorDescriptionTextInputModule(TextInputModule.Builder builder) Constructs a newTextInputModulegiven a builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic TextInputModule.BuilderConstructs a newTextInputModulebuilder.voidDisplays the displayText given in the constructor forTextInputModule.Builder, collects input from the scanner given inTUIModule.Builder.scanner(Scanner)then updates the application it's tied to store the input (This can be accessed viaApplicationModule.getInput(String)).getInput()Retrieve the input collected ondoRunLogic().booleanstructuralEquals(TextInputModule other) Checks equality for properties given by the builder.Methods inherited from class com.calebleavell.jatui.modules.TUIModule
getAnsi, getAnsiEnabled, getApplication, getChild, getChild, getChildren, getCurrentRunningBranch, getCurrentRunningChild, getCurrentRunningChild, getName, getPrintStream, getScanner, navigateTo, restart, restartChild, shallowStructuralEquals, start, structuralEquals, terminate, terminateChild, toString, toTreeString, toTreeString
-
Field Details
-
INVALID
A basic default error message if input is determined to be invalid via an InputHandler or something else.- See Also:
-
-
Constructor Details
-
TextInputModule
Constructs a newTextInputModulegiven a builder. CopiesdisplayTextfrom the builder.- Parameters:
builder- The builder to construct the new module from.
-
-
Method Details
-
doRunLogic
public void doRunLogic()Displays the displayText given in the constructor forTextInputModule.Builder, collects input from the scanner given inTUIModule.Builder.scanner(Scanner)then updates the application it's tied to store the input (This can be accessed viaApplicationModule.getInput(String)).
If InputHandlers are provided viaTextInputModule.Builder.addHandler(FunctionModule.Builder)or a corresponding method, those are run immediately after this.- Specified by:
doRunLogicin classTUIModule
-
getInput
Retrieve the input collected ondoRunLogic(). Alternatively, this can be collected viaApplicationModule.getInput(String), orApplicationModule.getInput(String, Class)with the class set toString.class.- Returns:
- The string collected when running. Null if this module hasn't run yet.
-
structuralEquals
Checks equality for properties given by the builder. ForTextInputModule, this includesdisplayText, as well as other requirements provided byTUIModule.structuralEquals(TUIModule). -
builder
Constructs a newTextInputModulebuilder.- Parameters:
name- The name of the builder.displayText- The text that displays before getting input (e.g., "Your Input: ").- Returns:
- The new builder.
-