module documentation
(source)

This module provides some common functionality for the manipulation of formatting states.

Defining the mechanism by which text containing character attributes is constructed begins by subclassing CharacterAttributesMixin.

Defining how a single formatting state is to be serialized begins by subclassing _FormattingStateMixin.

Serializing a formatting structure is done with flatten.

See Also
twisted.conch.insults.helper._FormattingState
twisted.conch.insults.text._CharacterAttributes
twisted.words.protocols.irc._FormattingState
twisted.words.protocols.irc._CharacterAttributes
Class ​Character​Attributes​Mixin No summary
Class ​Default​Formatting​State A character attribute that does nothing, thus applying no attributes to text.
Function flatten Serialize a sequence of characters with attribute information
Class _​Attribute A text attribute.
Class _​Background​Color​Attr Background color attribute.
Class _​Color​Attr Generic color attribute.
Class _​Color​Attribute A color text attribute.
Class _​Foreground​Color​Attr Foreground color attribute.
Class _​Formatting​State​Mixin Mixin for the formatting state/attributes of a single character.
Class _​Normal​Attr A text attribute for normal text.
Class _​Other​Attr A text attribute for text with formatting attributes.
def flatten(output, attrs, attributeRenderer='toVT102'): (source)

Serialize a sequence of characters with attribute information

The resulting string can be interpreted by compatible software so that the contained characters are displayed and, for those attributes which are supported by the software, the attributes expressed. The exact result of the serialization depends on the behavior of the method specified by attributeRenderer.

For example, if your terminal is VT102 compatible, you might run this for a colorful variation on the "hello world" theme:

    from twisted.conch.insults.text import flatten, attributes as A
    from twisted.conch.insults.helper import CharacterAttribute
    print(flatten(
        A.normal[A.bold[A.fg.red['He'], A.fg.green['ll'], A.fg.magenta['o'], ' ',
                        A.fg.yellow['Wo'], A.fg.blue['rl'], A.fg.cyan['d!']]],
        CharacterAttribute()))
Parameters
outputObject returned by accessing attributes of the module-level attributes object.
attrsA formatting state instance used to determine how to serialize output.
attribute​Renderer:strName of the method on attrs that should be called to render the attributes during serialization. Defaults to 'toVT102'.
Returns
A string expressing the text and display attributes specified by output.