Skip to content

Commit 6007248

Browse files
authored
Fix displaying bright color variation in terminal output (Gallopsled#2373)
* Recompute text.has_bright when num_colors changes The number of simultaneous colors in the current terminal are queried later during initialization and the text.num_colors attribute is updated accordingly. The text.has_bright attribute wasn't updated when that happened and always remained set to False. Calculate those properties based on num_colors dynamically. * Update CHANGELOG * Enable bright colors on Windows too Only get "colors" on Windows to avoid Gallopsled#1201 again. * Fix support for old terminals on windows
1 parent f046fdd commit 6007248

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ The table below shows which release corresponds to each branch, and what date th
129129
[2347]: https://github.com/Gallopsled/pwntools/pull/2347
130130
[2233]: https://github.com/Gallopsled/pwntools/pull/2233
131131

132+
## 4.12.1
133+
- [#2373][2373] Fix displaying bright color variation in terminal output
134+
135+
[2373]: https://github.com/Gallopsled/pwntools/pull/2373
136+
132137
## 4.12.0 (`stable`)
133138

134139
- [#2202][2202] Fix `remote` and `listen` in sagemath

pwnlib/term/text.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class Module(types.ModuleType):
2727
def __init__(self):
2828
self.__file__ = __file__
2929
self.__name__ = __name__
30-
self.num_colors = 8
31-
self.has_bright = self.num_colors >= 16
32-
self.has_gray = self.has_bright
30+
self.num_colors = termcap.get('colors', 8) if sys.platform == 'win32' else 8
3331
self.when = 'auto'
3432
self._colors = {
3533
'black': 0,
@@ -61,6 +59,14 @@ def when(self):
6159
def when(self, val):
6260
self._when = eval_when(val)
6361

62+
@property
63+
def has_bright(self):
64+
return self.num_colors >= 16
65+
66+
@property
67+
def has_gray(self):
68+
return self.has_bright
69+
6470
def _fg_color(self, c):
6571
c = termcap.get('setaf', c) or termcap.get('setf', c)
6672
if not hasattr(c, 'encode'):

0 commit comments

Comments
 (0)