From 524af9b4236ec347e9e783e57a166ed3eb1c600b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 20 Oct 2014 23:01:19 -0400 Subject: don't expose the vt100_color class --- t/basic_test.py | 8 ++++---- t/escape_test.py | 18 ++++++------------ t/init_test.py | 6 ++---- vt100/__init__.py | 28 +++++++++------------------- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/t/basic_test.py b/t/basic_test.py index cf790ba..eb2a1a9 100644 --- a/t/basic_test.py +++ b/t/basic_test.py @@ -8,8 +8,8 @@ class BasicTest(unittest.TestCase): string = b"foo\033[31m\033[32mb\033[3;7;42ma\033[23mr" vt.process(string) assert vt.get_string_plaintext(0, 0, 0, 50) == "foobar\n" - assert vt.cell(0, 0).fgcolor().color() is None - assert vt.cell(0, 3).fgcolor().color() == 2 - assert vt.cell(0, 4).fgcolor().color() == 2 - assert vt.cell(0, 4).bgcolor().color() == 2 + assert vt.cell(0, 0).fgcolor() is None + assert vt.cell(0, 3).fgcolor() == 2 + assert vt.cell(0, 4).fgcolor() == 2 + assert vt.cell(0, 4).bgcolor() == 2 assert vt.cell(0, 4).italic() diff --git a/t/escape_test.py b/t/escape_test.py index ed5c169..947bf8b 100644 --- a/t/escape_test.py +++ b/t/escape_test.py @@ -26,10 +26,8 @@ class EscapeTest(VT100Test): assert self.vt.title() == "" assert self.vt.icon_name() == "" - color = self.vt.default_fgcolor() - assert color.color() is None - color = self.vt.default_bgcolor() - assert color.color() is None + assert self.vt.default_fgcolor() is None + assert self.vt.default_bgcolor() is None assert not self.vt.default_bold() assert not self.vt.default_italic() @@ -62,10 +60,8 @@ class EscapeTest(VT100Test): assert self.vt.title() == "window title" assert self.vt.icon_name() == "window icon name" - color = self.vt.default_fgcolor() - assert color.color() is 1 - color = self.vt.default_bgcolor() - assert color.color() is 7 + assert self.vt.default_fgcolor() == 1 + assert self.vt.default_bgcolor() == 7 assert self.vt.default_bold() assert self.vt.default_italic() @@ -99,10 +95,8 @@ class EscapeTest(VT100Test): assert self.vt.title() == "window title" assert self.vt.icon_name() == "window icon name" - color = self.vt.default_fgcolor() - assert color.color() is None - color = self.vt.default_bgcolor() - assert color.color() is None + assert self.vt.default_fgcolor() is None + assert self.vt.default_bgcolor() is None assert not self.vt.default_bold() assert not self.vt.default_italic() diff --git a/t/init_test.py b/t/init_test.py index bc8084e..c4b8b48 100644 --- a/t/init_test.py +++ b/t/init_test.py @@ -24,10 +24,8 @@ class InitTest(VT100Test): assert self.vt.title() == "" assert self.vt.icon_name() == "" - color = self.vt.default_fgcolor() - assert color.color() is None - color = self.vt.default_bgcolor() - assert color.color() is None + assert self.vt.default_fgcolor() is None + assert self.vt.default_bgcolor() is None assert not self.vt.default_bold() assert not self.vt.default_italic() diff --git a/vt100/__init__.py b/vt100/__init__.py index d84a1e5..7b4fd6e 100644 --- a/vt100/__init__.py +++ b/vt100/__init__.py @@ -30,26 +30,16 @@ class vt100_color(Union): ("_id", c_uint32), ] - def type(self): - if self._type == 0: - return "default" - elif self._type == 1: - return "indexed" - elif self._type == 2: - return "rgb" - else: - raise Exception("unknown color type: %d" % self._type) - def color(self): - color_type = self.type() - if color_type == "default": + color_type = self._type + if color_type == 0: return None - elif color_type == "indexed": + elif color_type == 1: return self._idx - elif color_type == "rgb": + elif color_type == 2: return (self._r, self._g, self._b) else: - raise Exception("unknown color type: %s" % color_type) + raise Exception("unknown color type: %d" % color_type) class vt100_named_attrs(Structure): _fields_ = [ @@ -86,10 +76,10 @@ class vt100_cell(Structure): return self._contents[:self._len].decode('utf-8') def fgcolor(self): - return self._attrs._fgcolor + return self._attrs._fgcolor.color() def bgcolor(self): - return self._attrs._bgcolor + return self._attrs._bgcolor.color() def all_attrs(self): return self._attrs._attrs @@ -219,10 +209,10 @@ class vt100(object): return icon_name_str[:self.screen._icon_name_len].decode('utf-8') def default_fgcolor(self): - return self.screen._attrs._fgcolor + return self.screen._attrs._fgcolor.color() def default_bgcolor(self): - return self.screen._attrs._bgcolor + return self.screen._attrs._bgcolor.color() def all_default_attrs(self): return self.screen._attrs._attrs -- cgit v1.2.3