Package sc2002.FCS1.grp2.builders
Class Style.Builder
Object
Builder
- Enclosing class:
Style
The fancy formatted text builder.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static StringANSI ESC code prefix.ANSI code numbers to be applied for the current text.private StringThe current, un-finalised text.private StringThe contents including ANSI escape codes.private static StringThe code to be used to terminate the ESC code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd256Colour(int code, boolean atBackground) Apply a colour to the current text, either as label colour or at background.bold()Set the current text to bold.code(Style.Code code) Apply an ANSI codeitalic()Set the current text to italics.newLine()Go to new line.voidprint()Print formatted content directly in console.private voidprocess()Finalise everything, in preparation for export.Apply a strikethrough effect to the current text.Add a text.toString()Export the formatted content as a string.Underline the current text.
-
Field Details
-
result
The contents including ANSI escape codes. -
currentCodes
ANSI code numbers to be applied for the current text. -
currentText
The current, un-finalised text. -
base
ANSI ESC code prefix. -
terminator
The code to be used to terminate the ESC code.
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
bold
Set the current text to bold.- Returns:
- this builder object.
-
italic
Set the current text to italics.- Returns:
- this builder object.
-
underline
Underline the current text.- Returns:
- this builder object.
-
strikethrough
Apply a strikethrough effect to the current text.- Returns:
- this builder object.
-
code
Apply an ANSI code- Parameters:
code- The code to be applied (format or colour)- Returns:
- this builder object.
-
add256Colour
Apply a colour to the current text, either as label colour or at background.- Parameters:
code- The colour code to be applied (You may need to refer to colour chart)atBackground- Passtrue, if apply at background,falseto apply to text.- Returns:
- this builder object.
-
text
Add a text. Whenever you call this, it will finalise all formattings in the previous text. This lets you to chain and create texts of different formattings in the same line.- Parameters:
text- The text to be styled.- Returns:
- this builder object.
-
newLine
Go to new line. (Add \n)- Returns:
- this builder object.
-
process
private void process()Finalise everything, in preparation for export. -
toString
Export the formatted content as a string. -
print
public void print()Print formatted content directly in console.
-