AttributedString

public class AttributedString : CustomDebugStringConvertible

AttributedString offers a simple way to markup strings to annotate them with terminal attributes and colors.

A convenient init (markup:) method is provided to create these easily using a simple markup system, inspired by the Spectre.Console markup, which is in turn inspired by BBCode. Unlike BBCode, does not use the word on the closing tag, it merely auto-closes.

  • Splits the attributed string using the specified separator character

    Declaration

    Swift

    public func split(separator: Character) -> [AttributedString]

    Parameters

    separator

    The character to use to split

    Return Value

    An array of AttributedStrings

  • Constructs a new AttributedString from a marked-up string.

    The syntax allowed is: [color] - to specify the use of a color. [color on color] to specify the foreground and background colors. [bg=color] to specify a background color.

    Colors: black blue green cyan red magenta brown gray darkGray brightBlue brightGreen brightCyan brightRed brightMagenta brightYellow white

    Attributes: bold to specify the attribute should be bolded, on ANSI terminals this might merely make the color brighter. standout terminal-specific, it chooses a color that will standout. dim terminal-specific, it will choose a dimmer color. underline underlines the text. blink the character will be blinking. invert the character attributed will be inverted.

    Requests to use the colors define by the current color scheme: base the ColorScheme.normal if unfocused, or ColorScheme.focus if focused. hotBase the ColorScheme.hotNormal if unfocused, or ColorScheme.hotFocus if focused. normal the ColorScheme.normal attribute. focus the ColorScheme.focus attribute. hotNormal the ColorSchem.hotNormal attribute. hotFocus the ColorScheme.hotFocus attribute.

    Example: [red]This is Red[/][white on red]This looks like a warning[/][underline]this has a line under it[/]

    Declaration

    Swift

    public init(markup text: String)

    Parameters

    markup

    A string containing markup sequences

  • Creates an attributed string with no attributes defined

    Declaration

    Swift

    public init(text: String)

    Parameters

    text

    the text to use as the source of the attributes

  • Returns a new AttributedString that has been aligned given the specified width

    Declaration

    Swift

    public func align(to: TextAlignment, width: Int) -> AttributedString

    Parameters

    to

    the desired text alignment

    width

    the witdth to which the text should be rendered

    Return Value

    a new attributed string with the specified alignment

  • Formats an attributed string given the specified LineBreakMode

    Declaration

    Swift

    public static func format(_ string: AttributedString, with: LineBreakMode, width: Int, height: Int) -> [AttributedString]
  • Invoke this method to draw the attributed string at the current position on the painter.

    If the attributed string contains newlines the painter will go to the next line, preserving the initial column where this was called.

    Declaration

    Swift

    public func draw(on painter: Painter)

    Parameters

    painter

    The target painter where the string will be rendered

  • Returns the string, without attributes

    Declaration

    Swift

    public func toString() -> String
  • Declaration

    Swift

    public var debugDescription: String { get }