Class Style.Builder

Object
Builder
Enclosing class:
Style

public static class Style.Builder extends Object
The fancy formatted text builder.
  • Field Details

    • result

      private String result
      The contents including ANSI escape codes.
    • currentCodes

      private List<Integer> currentCodes
      ANSI code numbers to be applied for the current text.
    • currentText

      private String currentText
      The current, un-finalised text.
    • base

      private static String base
      ANSI ESC code prefix.
    • terminator

      private static String terminator
      The code to be used to terminate the ESC code.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • bold

      public Style.Builder bold()
      Set the current text to bold.
      Returns:
      this builder object.
    • italic

      public Style.Builder italic()
      Set the current text to italics.
      Returns:
      this builder object.
    • underline

      public Style.Builder underline()
      Underline the current text.
      Returns:
      this builder object.
    • strikethrough

      public Style.Builder strikethrough()
      Apply a strikethrough effect to the current text.
      Returns:
      this builder object.
    • code

      public Style.Builder code(Style.Code code)
      Apply an ANSI code
      Parameters:
      code - The code to be applied (format or colour)
      Returns:
      this builder object.
    • add256Colour

      public Style.Builder add256Colour(int code, boolean atBackground)
      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 - Pass true, if apply at background, false to apply to text.
      Returns:
      this builder object.
    • text

      public Style.Builder text(String 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

      public Style.Builder newLine()
      Go to new line. (Add \n)
      Returns:
      this builder object.
    • process

      private void process()
      Finalise everything, in preparation for export.
    • toString

      public String toString()
      Export the formatted content as a string.
      Overrides:
      toString in class Object
      Returns:
      formatted text content, ready for further printing.
    • print

      public void print()
      Print formatted content directly in console.