picocli

## Class CommandLine.Help.Ansi.Text

- java.lang.Object
- - picocli.CommandLine.Help.Ansi.Text

- All Implemented Interfaces:
    Cloneable
  Enclosing class:
    CommandLine.Help.Ansi

      public class CommandLine.Help.Ansi.Text
      extends Object
      implements Cloneable

  Encapsulates rich text with styles and colors. Text objects may be constructed with Strings containing markup like `@|bg(red),white,underline some text|@`, and this class converts the markup to ANSI escape codes.

  Internally keeps both an enriched and a plain text representation to allow layout components to calculate text width while remaining unaware of the embedded ANSI escape codes.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Text(CommandLine.Help.Ansi.Text other)` Copy constructor.
    `Text(int maxLength)` Constructs a Text with the specified max length (for use in a TextTable Column).
    `Text(String input)` Constructs a Text with the specified String, which may contain markup like `@|bg(red),white,underline some text|@`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `CommandLine.Help.Ansi.Text` | `append(CommandLine.Help.Ansi.Text text)` Deprecated. use `#concat(Text)` instead
    `CommandLine.Help.Ansi.Text` | `append(String string)` Deprecated. use `concat(String)` instead
    `Object` | `clone()`
    `CommandLine.Help.Ansi.Text` | `concat(CommandLine.Help.Ansi.Text other)` Returns a copy of this `Text` instance with the specified text concatenated to the end.
    `CommandLine.Help.Ansi.Text` | `concat(String string)` Returns a copy of this `Text` instance with the specified text concatenated to the end.
    `boolean` | `equals(Object obj)`
    `void` | `getStyledChars(int from, int length, CommandLine.Help.Ansi.Text destination, int offset)` Copies the specified substring of this Text into the specified destination, preserving the markup.
    `int` | `hashCode()`
    `String` | `plainString()` Returns the plain text without any formatting.
    `CommandLine.Help.Ansi.Text[]` | `splitLines()`
    `CommandLine.Help.Ansi.Text` | `substring(int start)` Returns a new `Text` instance that is a substring of this Text.
    `CommandLine.Help.Ansi.Text` | `substring(int start, int end)` Returns a new `Text` instance that is a substring of this Text.
    `String` | `toString()` Returns a String representation of the text with ANSI escape codes embedded, unless ANSI is CommandLine.Help.Ansi.enabled() not enabled}, in which case the plain text is returned.

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Text

          public Text(int maxLength)

      Constructs a Text with the specified max length (for use in a TextTable Column).
      Parameters:
        `maxLength` - max length of this text

    - #### Text

          public Text(CommandLine.Help.Ansi.Text other)

      Copy constructor.
      Since:
        3.9

    - #### Text

          public Text(String input)

      Constructs a Text with the specified String, which may contain markup like `@|bg(red),white,underline some text|@`.
      Parameters:
        `input` - the string with markup to parse

  - ### Method Detail

    - #### clone

          public Object clone()

      Overrides:
        `clone` in class `Object`

    - #### splitLines

          public CommandLine.Help.Ansi.Text[] splitLines()

    - #### substring

          public CommandLine.Help.Ansi.Text substring(int start)

      Returns a new `Text` instance that is a substring of this Text. Does not modify this instance!
      Parameters:
        `start` - index in the plain text where to start the substring
      Returns:
        a new Text instance that is a substring of this Text

    - #### substring

          public CommandLine.Help.Ansi.Text substring(int start,
                                                      int end)

      Returns a new `Text` instance that is a substring of this Text. Does not modify this instance!
      Parameters:
        `start` - index in the plain text where to start the substring
        `end` - index in the plain text where to end the substring
      Returns:
        a new Text instance that is a substring of this Text

    - #### append

          @Deprecated
          public CommandLine.Help.Ansi.Text append(String string)

      Deprecated. use `concat(String)` instead

    - #### append

          @Deprecated
          public CommandLine.Help.Ansi.Text append(CommandLine.Help.Ansi.Text text)

      Deprecated. use `#concat(Text)` instead

    - #### concat

          public CommandLine.Help.Ansi.Text concat(String string)

      Returns a copy of this `Text` instance with the specified text concatenated to the end. Does not modify this instance!
      Parameters:
        `string` - the text to concatenate to the end of this Text
      Returns:
        a new Text instance
      Since:
        3.0

    - #### concat

          public CommandLine.Help.Ansi.Text concat(CommandLine.Help.Ansi.Text other)

      Returns a copy of this `Text` instance with the specified text concatenated to the end. Does not modify this instance!
      Parameters:
        `other` - the text to concatenate to the end of this Text
      Returns:
        a new Text instance
      Since:
        3.0

    - #### getStyledChars

          public void getStyledChars(int from,
                                     int length,
                                     CommandLine.Help.Ansi.Text destination,
                                     int offset)

      Copies the specified substring of this Text into the specified destination, preserving the markup.
      Parameters:
        `from` - start of the substring
        `length` - length of the substring
        `destination` - destination Text to modify
        `offset` - indentation (padding)

    - #### plainString

          public String plainString()

      Returns the plain text without any formatting.
      Returns:
        the plain text without any formatting

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Returns a String representation of the text with ANSI escape codes embedded, unless ANSI is CommandLine.Help.Ansi.enabled() not enabled}, in which case the plain text is returned.
      Overrides:
        `toString` in class `Object`
      Returns:
        a String representation of the text with ANSI escape codes embedded (if enabled)

Copyright © 2019. All rights reserved.