Skip to content

Commit c7f70d2

Browse files
committed
Document color controls, allow doctests in the docs directory.
1 parent 221813d commit c7f70d2

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

docs/glossary.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,4 @@ Glossary
6060
color control
6161
color controls
6262
Libtcod's old system which assigns colors to specific codepoints.
63-
This is deprecated in favor of the codes which set the foreground and
64-
background colors directly.
63+
See :any:`tcod.COLCTRL_STOP`, :any:`tcod.COLCTRL_FORE_RGB`, and :any:`tcod.COLCTRL_BACK_RGB` for examples.

docs/libtcodpy.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,45 @@ color
4747

4848
color controls
4949
~~~~~~~~~~~~~~
50-
Configurable color control constants which can be set up with
51-
:any:`tcod.console_set_color_control`.
50+
Libtcod color control constants.
51+
These can be inserted into Python strings with the ``%c`` format specifier as shown below.
5252

5353
.. data:: tcod.COLCTRL_1
54+
55+
These can be configured with :any:`tcod.console_set_color_control`.
56+
However, it is recommended to use :any:`tcod.COLCTRL_FORE_RGB` and :any:`tcod.COLCTRL_BACK_RGB` instead.
57+
5458
.. data:: tcod.COLCTRL_2
5559
.. data:: tcod.COLCTRL_3
5660
.. data:: tcod.COLCTRL_4
5761
.. data:: tcod.COLCTRL_5
5862

5963
.. data:: tcod.COLCTRL_STOP
64+
65+
When this control character is inserted into a string the foreground and background colors will be reset for the
66+
remaining characters of the string.
67+
68+
>>> import tcod
69+
>>> reset_color = f"{tcod.COLCTRL_STOP:c}"
70+
6071
.. data:: tcod.COLCTRL_FORE_RGB
72+
73+
Sets the foreground color to the next 3 Unicode characters for the remaining characters.
74+
75+
>>> fg = (255, 255, 255)
76+
>>> change_fg = f"{tcod.COLCTRL_FORE_RGB:c}{fg[0]:c}{fg[1]:c}{fg[2]:c}"
77+
>>> string = f"Old color {change_fg}new color{tcod.COLCTRL_STOP:c} old color."
78+
6179
.. data:: tcod.COLCTRL_BACK_RGB
6280

81+
Sets the background color to the next 3 Unicode characters for the remaining characters.
82+
83+
>>> from typing import Tuple
84+
>>> def change_colors(fg: Tuple[int, int, int], bg: Tuple[int, int, int]) -> str:
85+
... """Return the control codes to change the foreground and background colors."""
86+
... return "%c%c%c%c%c%c%c%c" % (tcod.COLCTRL_FORE_RGB, *fg, tcod.COLCTRL_BACK_RGB, *bg)
87+
>>> string = f"Old {change_colors(fg=(255, 255, 255), bg=(0, 0, 255))}new"
88+
6389
console
6490
-------
6591

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ test=pytest
1212
addopts=
1313
tcod/
1414
tests/
15+
docs/
1516
--doctest-modules
17+
--doctest-glob="*.rst"
1618
--cov=tcod
1719
--capture=sys
1820
--ignore=tcod/__pyinstaller

0 commit comments

Comments
 (0)