From c1fdf21a4db820dccf18a80df6c33d7e47fb4bf5 Mon Sep 17 00:00:00 2001 From: Avram Lubkin Date: Sun, 16 Jan 2022 21:14:52 -0500 Subject: [PATCH] Treat 88 colors as 16 colors --- blessed/terminal.py | 12 ++++++++++-- tests/test_color.py | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/blessed/terminal.py b/blessed/terminal.py index b8b1240..38bd2bb 100644 --- a/blessed/terminal.py +++ b/blessed/terminal.py @@ -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 diff --git a/tests/test_color.py b/tests/test_color.py index 7852e87..44e9d4d 100644 --- a/tests/test_color.py +++ b/tests/test_color.py @@ -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