Skip to content

Commit

Permalink
Treat 88 colors as 16 colors
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Jan 20, 2022
1 parent 165f43d commit c1fdf21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions blessed/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,13 +938,21 @@ def number_of_colors(self):
This may be used to test whether the terminal supports colors,
and at what depth, if that's a concern.
If this property is assigned a value of 88, the value 16 will be saved. This is due to the
the rarity of 88 color support and the inconsistency of behavior between implementations.
Assigning this property to a value other than 0, 4, 8, 16, 88, 256, or 1 << 24 will
raise an :py:exc:`AssertionError`.
"""
return self._number_of_colors

@number_of_colors.setter
def number_of_colors(self, value):
assert value in (0, 4, 8, 16, 256, 1 << 24)
self._number_of_colors = value
assert value in (0, 4, 8, 16, 88, 256, 1 << 24)
# Because 88 colors is rare and we can't guarantee consistent behavior,
# when 88 colors is detected, it is treated as 16 colors
self._number_of_colors = 16 if value == 88 else value
self.__clear_color_capabilities()

@property
Expand Down
4 changes: 4 additions & 0 deletions tests/test_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def child():
t.number_of_colors = num
assert t.number_of_colors == num
assert 'aqua' not in dir(t)

t.number_of_colors = 88
assert t.number_of_colors == 16

with pytest.raises(AssertionError):
t.number_of_colors = 40

Expand Down

0 comments on commit c1fdf21

Please sign in to comment.