Package com.calebleavell.jatui.templates
Class TextChain
- All Implemented Interfaces:
DirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, TextChain>
Simplifies chaining text together that is meant to live on the same line.
Ansi is supported with method overloads (e.g.,
Usage:
addText(String, Ansi)).
Usage:
LineBuilder text = LineBuilder.builder("name")
.addText("Regular text: ")
// this will display what the inputted module outputs
.addModuleOutput("This string is the name of another module")
.newLine() // end of line 1
.addText("Text on the next line.")
.newLine(); // end of line 2
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
DirectedGraphNode.PropertyUpdateFlag -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intAppended to the name of every newTextModuleand incremented.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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddModuleOutput(String moduleName) Displays the output of the module with namemoduleName.addModuleOutput(String moduleName, org.fusesource.jansi.Ansi ansi) Displays the output of the module with namemoduleName.addText(TextModule.Builder text) Addstextas a child of this module.Adds a newTextModuleas a child of this module.Adds a newTextModuleas a child of this module.static TextChainConstructs a newTextChainbuilder.protected TextChainGets a fresh instance of this type of Builder.protected TextModule.Buildercurrentis a reference of the most recently added text is saved to callTextModule.Builder.printNewLine(boolean)ifnewLine()is called.newLine()Prints an os-defined newline.voidshallowCopy(TextChain original) Copies the reference to the most recently added module and the naming iterator, and delegates toTUIModule.Builder.shallowCopy(TUIModule.Builder).booleanshallowStructuralEquals(TextChain first, TextChain second) Checks equality for properties given by the builder.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, name, 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
-
Field Details
-
iterator
protected int iteratorAppended to the name of every newTextModuleand incremented. The name of every text module follows "[LineBuilder name]-main-[iterator]".
-
-
Constructor Details
-
TextChain
-
TextChain
protected TextChain()
-
-
Method Details
-
builder
Constructs a newTextChainbuilder.- Parameters:
name- The name of the builder.- 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<TextChain>- Returns:
- A fresh, empty instance.
-
shallowCopy
Copies the reference to the most recently added module and the naming iterator, and delegates toTUIModule.Builder.shallowCopy(TUIModule.Builder).- Overrides:
shallowCopyin classTUIModule.Builder<TextChain>- Parameters:
original- The builder to copy from.
-
addText
Addstextas a child of this module.- Parameters:
text- TheTextModuleto add.- Returns:
- self
- Implementation Note:
- Adds
textas a child ofmainrather than directly to this module.
-
addText
Adds a newTextModuleas a child of this module. To print a new line after this text, callnewLine().- Parameters:
text- The text to add.ansi- TheAnsithat this text may use. Ansi is reset automatically aftertextis displayed.- Returns:
- self.
-
addText
Adds a newTextModuleas a child of this module. To print a new line after this text, callnewLine().- Parameters:
text- The text to add.- Returns:
- self.
-
addModuleOutput
Displays the output of the module with namemoduleName. More precisely, it displays the application state that is accessed atApplicationModule.getInput(String).- Parameters:
moduleName- The input identifier for the application state (likely the name of another module).ansi- TheAnsithat this text may use. Ansi is reset automatically after text is displayed.- Returns:
- self
- Implementation Note:
- Wraps
TextModule.OutputType.DISPLAY_APP_STATE.
-
addModuleOutput
Displays the output of the module with namemoduleName. More precisely, it displays the application state that is accessed atApplicationModule.getInput(String).- Parameters:
moduleName- The input identifier for the application state (likely the name of another module).- Returns:
- self
- Implementation Note:
- Wraps
TextModule.OutputType.DISPLAY_APP_STATE.
-
newLine
Prints an os-defined newline.
Example:LineBuilder text = LineBuilder.builder("name") .newLine() .addText("Hello, ") .addText("World!") .newLine(); text.build().run(); // output: "\nHello, World!\n"- Returns:
- self
- Implementation Note:
- If text has been added, it sets the most recently added
TextModuleto print a newline. If not, it adds a new emptyTextModuleand sets it to print a newline.TextModuleusesPrintStream.println().
-
getCurrent
currentis a reference of the most recently added text is saved to callTextModule.Builder.printNewLine(boolean)ifnewLine()is called.- Returns:
- current;
-
shallowStructuralEquals
Checks equality for properties given by the builder. ForTextChain, this includescurrentanditerator, as well as other requirements provided byTUIModule.Builder.shallowStructuralEquals(TUIModule.Builder, TUIModule.Builder).- Specified by:
shallowStructuralEqualsin interfaceDirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, TextChain> - Overrides:
shallowStructuralEqualsin classTUIModule.Builder<TextChain>- Parameters:
first- The first TUIModule to comparesecond- The second TUIModule to compare- Returns:
trueiffirstandsecondare equal according to builder-provided properties
-