Skip to content

Commit ff757e5

Browse files
committed
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.
1 parent f046fdd commit ff757e5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pwnlib/term/text.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ def __init__(self):
2828
self.__file__ = __file__
2929
self.__name__ = __name__
3030
self.num_colors = 8
31-
self.has_bright = self.num_colors >= 16
32-
self.has_gray = self.has_bright
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)