@@ -47,19 +47,45 @@ color
4747
4848color 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+
6389console
6490-------
6591
0 commit comments