summaryrefslogtreecommitdiff
path: root/docs/textattributes.txt
blob: 97b2e47093bc3dbd86f00f3718e64b9d0d851162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
.. _text-attributes:

Text Attributes
---------------

A `Text` widget can take plain or unicode strings, but you can also specify which 
attributes to display each part of that text by using "text markup" format.  Text
markup made up of lists and tuples.  Tuples contain an attribute and text markup to
apply it to.  Lists used to concatenate text markup.

The normal text formatting rules apply and the attributes will follow the text
when it is split or wrapped to the next line.

`Text reference <http://excess.org/urwid/reference.html#Text>`_

::

    Text("a simple string with default attributes")


The string and space around will appear in the default foreground and
background.

::

    Text(('attr1', "a string in attribute attr1"))


The string will appear with foreground and backgrounds specified in the display 
module's palette for ``'attr1'``, but the space around (before/after) the text will
appear with the default foreground and background.

If you want the whole :class:`Text` widget, including the space around the
text, to appear as a single attribute you should put your widget inside an
:class:`AttrMap` widget.

`AttrMap reference <http://excess.org/urwid/reference.html#AttrMap>`_

::

    Text(["a simple string ", ('attr1', "ending in attr1")])


The first three words have the default attribute and the last three words have
attribute ``'attr1'``.

::

    Text([('attr1', "start in attr1 "), ('attr2', "end in attr2")])


The first three words have attribute ``'attr1'`` and the last three words have
attribute ``'attr2'``.

::

    Text(('attr1', ["nesting example ", ('attr2', "inside"), " outside"]))


When markup is nested only the innermost attribute applies.  Here ``"inside"`` has
attribute ``'attr2'`` and all the rest of the text has attribute ``'attr1'``.

.. vim: set ft=rst: