Package com.calebleavell.jatui.templates
Class ConfirmationPrompt
java.lang.Object
com.calebleavell.jatui.modules.TUIModule.Builder<ConfirmationPrompt>
com.calebleavell.jatui.modules.ModuleTemplate<ConfirmationPrompt>
com.calebleavell.jatui.templates.ConfirmationPrompt
- All Implemented Interfaces:
DirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, ConfirmationPrompt>
Handles getting confirmation from the user. Includes specifying allowed responses
(y/yes/n/no) by default, as well on what to do when the user confirms or denies.
Example Usage:
Example Usage:
ConfirmationPrompt confirmExit = ConfirmationPrompt.builder("confirm-exit",
"Are you sure you want to exit (y/n)? ")
.setApplication(app)
.addOnConfirm(app::terminate)
.addOnDeny(app::restart);
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
DirectedGraphNode.PropertyUpdateFlag -
Field Summary
Fields inherited from class com.calebleavell.jatui.modules.ModuleTemplate
mainFields inherited from class com.calebleavell.jatui.modules.TUIModule.Builder
ansi, application, children, enableAnsi, logger, name, printStream, propertyUpdateFlags, scanner, type, usedNames -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedConfirmationPrompt(String name, String displayText) -
Method Summary
Modifier and TypeMethodDescriptionaddOnConfirm(Runnable logic) Specifies what to do when the user confirms.addOnConfirm(String name, Supplier<?> logic) Specifies what to do when the user confirms.Specifies what to do when the user denies.Specifies what to do when the user denies.static ConfirmationPromptConstructs a newConfirmationPromptbuilder.protected ConfirmationPromptGets a fresh instance of this type of Builder.Gets the inputs that are considered confirmation from the user (yes/y) by default.Gets the inputs that are considered denial from the user (no/n) by default.Sets the name as provided byTUIModule.Builder.name(String).voidshallowCopy(ConfirmationPrompt original) Copies valid confirmation and denial inputs, the currentitersfor naming handlers, and delegates toTUIModule.Builder.shallowCopy(TUIModule.Builder).booleanshallowStructuralEquals(ConfirmationPrompt first, ConfirmationPrompt second) Checks equality for properties given by the builder.validConfirm(String... confirmStrings) Sets the strings that will count as a confirmation.Sets the strings that will count as a denial.Methods inherited from class com.calebleavell.jatui.modules.ModuleTemplate
build, deepCopyMethods inherited from class com.calebleavell.jatui.modules.TUIModule.Builder
addChild, addChild, addChildren, addChildren, appendStyle, application, clearChildren, deepCopy, enableAnsi, getAnsi, getAnsiEnabled, getApplication, getChild, getChild, getChildren, getCopy, getDeepCopy, getName, getPrintStream, getPropertyUpdateFlags, getScanner, getType, lockProperty, prependStyle, prependToName, printStream, scanner, self, structuralEquals, style, toString, unlockProperty, updateFlag, updatePropertiesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
abstractSelf, containsNullNode, containsNullNode, dfs, dfs, forEach, forEachChild, structuralEquals, structuralEquals, updateProperty, updateProperty
-
Constructor Details
-
ConfirmationPrompt
-
ConfirmationPrompt
protected ConfirmationPrompt()
-
-
Method Details
-
builder
Constructs a newConfirmationPromptbuilder.- Parameters:
name- The name of the builder.displayText- The text that displays before getting input (e.g., "Are you sure? ").- Returns:
- The new builder.
-
createInstance
Gets a fresh instance of this type of Builder. Note, this is intended only for copying utility and may have unknown consequences if used in other ways.- Specified by:
createInstancein classTUIModule.Builder<ConfirmationPrompt>- Returns:
- A fresh, empty instance.
-
validConfirm
Sets the strings that will count as a confirmation. Note, this clears the current confirmation strings.
Note: spaces are stripped from both these strings and the input, and both these strings and the input are converted to lowercase.- Parameters:
confirmStrings- The strings that count as confirmation- Returns:
- self
-
getValidConfirm
Gets the inputs that are considered confirmation from the user (yes/y) by default.- Returns:
- The valid confirmation strings.
-
validDeny
Sets the strings that will count as a denial. Note, this clears the current denial strings
Note: spaces are stripped from both these strings and the input, and both these strings and the input are converted to lowercase.- Parameters:
denyStrings- The strings that count as denial- Returns:
- self
-
getValidDeny
Gets the inputs that are considered denial from the user (no/n) by default.- Returns:
- The valid denial strings.
-
addOnConfirm
Specifies what to do when the user confirms.- Parameters:
logic- The logic to run on the input.- Returns:
- self
-
addOnConfirm
Specifies what to do when the user confirms.- Parameters:
name- The input identifier to access whatlogicreturns (ApplicationModule.getInput(String)).logic- The logic to run on the input.- Returns:
- self
-
addOnDeny
Specifies what to do when the user denies.- Parameters:
name- The input identifier to access whatlogicreturns (ApplicationModule.getInput(String)).logic- The logic to run on the input.- Returns:
- self
-
addOnDeny
Specifies what to do when the user denies.- Parameters:
logic- The logic to run on the input.- Returns:
- self
-
name
Sets the name as provided byTUIModule.Builder.name(String). Also updates the name of the input module to ensure correct input handling.- Overrides:
namein classTUIModule.Builder<ConfirmationPrompt>- Parameters:
name- The unique name of this module.- Returns:
- self
-
shallowStructuralEquals
Checks equality for properties given by the builder. ForConfirmationPrompt, this includesconfirm,deny,confirmIter, anddenyIter, as well as other requirements provided byTUIModule.Builder.shallowStructuralEquals(TUIModule.Builder, TUIModule.Builder).- Specified by:
shallowStructuralEqualsin interfaceDirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, ConfirmationPrompt> - Overrides:
shallowStructuralEqualsin classTUIModule.Builder<ConfirmationPrompt>- Parameters:
first- The first TUIModule to comparesecond- The second TUIModule to compare- Returns:
trueiffirstandsecondare equal according to builder-provided properties
-
shallowCopy
Copies valid confirmation and denial inputs, the currentitersfor naming handlers, and delegates toTUIModule.Builder.shallowCopy(TUIModule.Builder).- Overrides:
shallowCopyin classTUIModule.Builder<ConfirmationPrompt>- Parameters:
original- The builder to copy from.
-