Skip to content

Commit 079dd62

Browse files
committed
Deprecate fg, bg, bg_blend keywords in Console methods
1 parent c8103fd commit 079dd62

File tree

3 files changed

+104
-20
lines changed

3 files changed

+104
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
1313

1414
### Deprecated
1515

16-
- Using `Console.print` without keywords for only the `x`, `y`, and `text` parameters has been deprecated.
16+
- In general the `fg`, `bg`, and `bg_blend` keywords are too hard to keep track of as positional arguments so they must be replaced with keyword arguments instead.
17+
- `Console.print`: deprecated `string`, `fg`, `bg`, and `bg_blend` being given as positional arguments.
1718
The `string` parameter has been renamed to `text`.
1819
- `Console.print_box` has been replaced by `Console.print`.
20+
- `Console.draw_frame`: deprecated `clear`, `fg`, `bg`, and `bg_blend` being given as positional arguments.
21+
- `Console.draw_rect`: deprecated `fg`, `bg`, and `bg_blend` being given as positional arguments.
1922

2023
## [17.1.0] - 2025-03-29
2124

tcod/console.py

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ def vline(
743743
self.__deprecate_defaults("draw_rect", bg_blend)
744744
lib.TCOD_console_vline(self.console_c, x, y, height, bg_blend)
745745

746+
@deprecated("Replace with 'console.draw_frame(...)', use a separate print call for frame titles")
746747
def print_frame( # noqa: PLR0913
747748
self,
748749
x: int,
@@ -976,36 +977,36 @@ def __str__(self) -> str:
976977
return "<{}>".format("\n ".join("".join(chr(c) for c in line) for line in self._tiles["ch"]))
977978

978979
@overload
979-
@deprecated(
980-
"Switch all parameters to keywords such as 'console.print(x=..., y=..., text=..., width=..., height=..., fg=..., bg=..., bg_blend=..., alignment=...)'"
981-
"\n'string' keyword should be renamed to `text`"
982-
)
983980
def print(
984981
self,
985982
x: int,
986983
y: int,
987984
text: str,
985+
*,
986+
width: int | None = None,
987+
height: int | None = None,
988988
fg: tuple[int, int, int] | None = None,
989989
bg: tuple[int, int, int] | None = None,
990990
bg_blend: int = tcod.constants.BKGND_SET,
991991
alignment: int = tcod.constants.LEFT,
992-
*,
993-
string: str = "",
994992
) -> int: ...
995993

996994
@overload
995+
@deprecated(
996+
"Replace text, fg, bg, bg_blend, and alignment with keyword arguments."
997+
"\n'string' keyword should be renamed to `text`"
998+
)
997999
def print(
9981000
self,
9991001
x: int,
10001002
y: int,
10011003
text: str,
1002-
*,
1003-
width: int | None = None,
1004-
height: int | None = None,
10051004
fg: tuple[int, int, int] | None = None,
10061005
bg: tuple[int, int, int] | None = None,
10071006
bg_blend: int = tcod.constants.BKGND_SET,
10081007
alignment: int = tcod.constants.LEFT,
1008+
*,
1009+
string: str = "",
10091010
) -> int: ...
10101011

10111012
def print( # noqa: PLR0913
@@ -1036,11 +1037,15 @@ def print( # noqa: PLR0913
10361037
height: Height in tiles to constrain the printing region.
10371038
fg: RGB tuple to use as the foreground color, or `None` to leave the foreground unchanged.
10381039
Tuple values should be 0-255.
1040+
Must be given as a keyword argument.
10391041
bg: RGB tuple to use as the background color, or `None` to leave the foreground unchanged.
10401042
Tuple values should be 0-255.
1043+
Must be given as a keyword argument.
10411044
bg_blend: Background blend type used by libtcod.
10421045
Typically starts with `libtcodpy.BKGND_*`.
1046+
Must be given as a keyword argument.
10431047
alignment: One of `libtcodpy.LEFT`, `libtcodpy.CENTER`, or `libtcodpy.RIGHT`
1048+
Must be given as a keyword argument.
10441049
string: Older deprecated name of the `text` parameter.
10451050
10461051
Returns:
@@ -1086,13 +1091,16 @@ def print( # noqa: PLR0913
10861091
10871092
.. versionchanged:: Unreleased
10881093
1094+
Deprecated giving `string`, `fg`, `bg`, and `bg_blend` as positional arguments.
1095+
10891096
Added `text` parameter to replace `string`.
10901097
10911098
Added `width` and `height` keyword parameters to bind text to a rectangle and replace other print functions.
10921099
Right-aligned text with `width=None` now treats the `x` coordinate as a past-the-end index, this will shift
10931100
the text of older calls to the left by 1 tile.
10941101
1095-
Now returns the number of lines printed via word wrapping.
1102+
Now returns the number of lines printed via word wrapping,
1103+
same as previous print functions bound to rectangles.
10961104
"""
10971105
if width is not None and width <= 0:
10981106
return 0
@@ -1187,6 +1195,38 @@ def print_box( # noqa: PLR0913
11871195
)
11881196
)
11891197

1198+
@overload
1199+
def draw_frame(
1200+
self,
1201+
x: int,
1202+
y: int,
1203+
width: int,
1204+
height: int,
1205+
*,
1206+
clear: bool = True,
1207+
fg: tuple[int, int, int] | None = None,
1208+
bg: tuple[int, int, int] | None = None,
1209+
bg_blend: int = tcod.constants.BKGND_SET,
1210+
decoration: str | tuple[int, int, int, int, int, int, int, int, int] = "┌─┐│ │└─┘",
1211+
) -> None: ...
1212+
1213+
@overload
1214+
@deprecated("Parameters clear, fg, bg, bg_blend should be keyword arguments. Remove title parameter")
1215+
def draw_frame(
1216+
self,
1217+
x: int,
1218+
y: int,
1219+
width: int,
1220+
height: int,
1221+
title: str = "",
1222+
clear: bool = True, # noqa: FBT001, FBT002
1223+
fg: tuple[int, int, int] | None = None,
1224+
bg: tuple[int, int, int] | None = None,
1225+
bg_blend: int = tcod.constants.BKGND_SET,
1226+
*,
1227+
decoration: str | tuple[int, int, int, int, int, int, int, int, int] = "┌─┐│ │└─┘",
1228+
) -> None: ...
1229+
11901230
def draw_frame( # noqa: PLR0913
11911231
self,
11921232
x: int,
@@ -1215,13 +1255,16 @@ def draw_frame( # noqa: PLR0913
12151255
border with :any:`Console.print_box` using your own style.
12161256
12171257
If `clear` is True than the region inside of the frame will be cleared.
1258+
Must be given as a keyword argument.
12181259
12191260
`fg` and `bg` are the foreground and background colors for the frame
12201261
border. This is a 3-item tuple with (r, g, b) color values from
12211262
0 to 255. These parameters can also be set to `None` to leave the
12221263
colors unchanged.
1264+
Must be given as a keyword argument.
12231265
12241266
`bg_blend` is the blend type used by libtcod.
1267+
Must be given as a keyword argument.
12251268
12261269
`decoration` is a sequence of glyphs to use for rendering the borders.
12271270
This a str or tuple of int's with 9 items with the items arranged in
@@ -1241,6 +1284,10 @@ def draw_frame( # noqa: PLR0913
12411284
.. versionchanged:: 13.0
12421285
`x` and `y` are now always used as an absolute position for negative values.
12431286
1287+
.. versionchanged:: Unreleased
1288+
Deprecated `clear`, `fg`, `bg`, and `bg_blend` being given as positional arguments.
1289+
These should be keyword arguments only.
1290+
12441291
Example::
12451292
12461293
>>> from tcod import libtcodpy
@@ -1305,6 +1352,34 @@ def draw_frame( # noqa: PLR0913
13051352
)
13061353
)
13071354

1355+
@overload
1356+
def draw_rect(
1357+
self,
1358+
x: int,
1359+
y: int,
1360+
width: int,
1361+
height: int,
1362+
*,
1363+
ch: int,
1364+
fg: tuple[int, int, int] | None = None,
1365+
bg: tuple[int, int, int] | None = None,
1366+
bg_blend: int = tcod.constants.BKGND_SET,
1367+
) -> None: ...
1368+
1369+
@overload
1370+
@deprecated("Parameters cg, fg, bg, bg_blend should be keyword arguments")
1371+
def draw_rect(
1372+
self,
1373+
x: int,
1374+
y: int,
1375+
width: int,
1376+
height: int,
1377+
ch: int,
1378+
fg: tuple[int, int, int] | None = None,
1379+
bg: tuple[int, int, int] | None = None,
1380+
bg_blend: int = tcod.constants.BKGND_SET,
1381+
) -> None: ...
1382+
13081383
def draw_rect( # noqa: PLR0913
13091384
self,
13101385
x: int,
@@ -1323,15 +1398,16 @@ def draw_rect( # noqa: PLR0913
13231398
13241399
`width` and `height` determine the size of the rectangle.
13251400
1326-
`ch` is a Unicode integer. You can use 0 to leave the current
1327-
characters unchanged.
1401+
`ch` is a Unicode integer. You can use 0 to leave the current characters unchanged.
1402+
Must be given as a keyword argument.
13281403
1329-
`fg` and `bg` are the foreground text color and background tile color
1330-
respectfully. This is a 3-item tuple with (r, g, b) color values from
1331-
0 to 255. These parameters can also be set to `None` to leave the
1332-
colors unchanged.
1404+
`fg` and `bg` are the foreground text color and background tile color respectfully.
1405+
This is a 3-item tuple with (r, g, b) color values from 0 to 255.
1406+
These parameters can also be set to `None` to leave the colors unchanged.
1407+
Must be given as a keyword argument.
13331408
13341409
`bg_blend` is the blend type used by libtcod.
1410+
Must be given as a keyword argument.
13351411
13361412
.. versionadded:: 8.5
13371413
@@ -1340,6 +1416,10 @@ def draw_rect( # noqa: PLR0913
13401416
13411417
.. versionchanged:: 13.0
13421418
`x` and `y` are now always used as an absolute position for negative values.
1419+
1420+
.. versionchanged:: Unreleased
1421+
Deprecated `ch`, `fg`, `bg`, and `bg_blend` being given as positional arguments.
1422+
These should be keyword arguments only.
13431423
"""
13441424
lib.TCOD_console_draw_rect_rgb(
13451425
self.console_c,

tests/test_console.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ def test_console_methods() -> None:
8181
console.hline(0, 1, 10)
8282
with pytest.deprecated_call():
8383
console.vline(1, 0, 10)
84-
console.print_frame(0, 0, 8, 8, "Frame")
85-
console.blit(0, 0, 0, 0, console, 0, 0) # type: ignore
86-
console.blit(0, 0, 0, 0, console, 0, 0, key_color=(0, 0, 0)) # type: ignore
84+
with pytest.deprecated_call():
85+
console.print_frame(0, 0, 8, 8, "Frame")
86+
console.blit(0, 0, 0, 0, console, 0, 0) # type: ignore[arg-type]
87+
console.blit(0, 0, 0, 0, console, 0, 0, key_color=(0, 0, 0)) # type: ignore[arg-type]
8788
with pytest.deprecated_call():
8889
console.set_key_color((254, 0, 254))
8990

0 commit comments

Comments
 (0)