Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix displaying bright color variation in terminal output #2373

Merged
merged 4 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ The table below shows which release corresponds to each branch, and what date th
[2347]: https://github.com/Gallopsled/pwntools/pull/2347
[2233]: https://github.com/Gallopsled/pwntools/pull/2233

## 4.12.1
- [#2373][2373] Fix displaying bright color variation in terminal output

[2373]: https://github.com/Gallopsled/pwntools/pull/2373

## 4.12.0 (`stable`)

- [#2202][2202] Fix `remote` and `listen` in sagemath
Expand Down
12 changes: 9 additions & 3 deletions pwnlib/term/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class Module(types.ModuleType):
def __init__(self):
self.__file__ = __file__
self.__name__ = __name__
self.num_colors = 8
self.has_bright = self.num_colors >= 16
self.has_gray = self.has_bright
self.num_colors = termcap.get('colors', 8) if sys.platform == 'win32' else 8
self.when = 'auto'
self._colors = {
'black': 0,
Expand Down Expand Up @@ -61,6 +59,14 @@ def when(self):
def when(self, val):
self._when = eval_when(val)

@property
def has_bright(self):
return self.num_colors >= 16

@property
def has_gray(self):
return self.has_bright

def _fg_color(self, c):
c = termcap.get('setaf', c) or termcap.get('setf', c)
if not hasattr(c, 'encode'):
Expand Down
Loading