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 Alsotwisted.conch.insults.helper._FormattingState
twisted.conch.insults.text._CharacterAttributes
twisted.words.protocols.irc._FormattingState
twisted.words.protocols.irc._CharacterAttributes
Class CharacterAttributesMixin No summary
Class DefaultFormattingState 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 _NormalAttr A text attribute for normal text.
Class _OtherAttr A text attribute for text with formatting attributes.
Class _ColorAttr Generic color attribute.
Class _ForegroundColorAttr Foreground color attribute.
Class _BackgroundColorAttr Background color attribute.
Class _ColorAttribute A color text attribute.
Class _FormattingStateMixin Mixin for the formatting state/attributes of a single character.
def flatten(output, attrs, attributeRenderer='toVT102'):

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()))
ParametersoutputObject returned by accessing attributes of the module-level attributes object.
attrsA formatting state instance used to determine how to serialize output.
attributeRendererName of the method on attrs that should be called to render the attributes during serialization. Defaults to 'toVT102'. (type: str)
ReturnsA string expressing the text and display attributes specified by output.
API Documentation for twisted, generated by pydoctor at 2020-03-25 17:34:30.