From b8fb407411a4e5c0ed52ec33dc3c52e68837e341 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Mon, 19 Dec 2016 20:13:21 +0100 Subject: fix broken color handling When printing "\e[32mx\e[33mx\e[32mx\e[0m", the expected outcome is that the first and third x share the same color. Prior to clearing A_COLOR, the colors would be ORed yielding three different colors. This breaks e.g. usage with mutt. --- tcvt.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tcvt.py') diff --git a/tcvt.py b/tcvt.py index f1af84e..3cdb957 100755 --- a/tcvt.py +++ b/tcvt.py @@ -90,6 +90,9 @@ class Simple: def attron(self, attr): self.screen.attron(attr) + def attroff(self, attr): + self.screen.attroff(attr) + def clrtoeol(self): self.screen.clrtoeol() @@ -223,6 +226,9 @@ class Columns: def attron(self, attr): self.attrs |= attr + def attroff(self, attr): + self.attrs &= ~attr + def clrtoeol(self): self.curwin.clrtoeol() @@ -603,15 +609,19 @@ class Terminal: self.screen.attrset(0) elif 30 <= code <= 37: self.fg = code - 30 + self.screen.attroff(curses.A_COLOR) self.screen.attron(get_color(self.fg, self.bg)) elif code == 39: self.fg = 7 + self.screen.attroff(curses.A_COLOR) self.screen.attron(get_color(self.fg, self.bg)) elif 40 <= code <= 47: self.bg = code - 40 + self.screen.attroff(curses.A_COLOR) self.screen.attron(get_color(self.fg, self.bg)) elif code == 49: self.bg = 0 + self.screen.attroff(curses.A_COLOR) self.screen.attron(get_color(self.fg, self.bg)) else: raise ValueError("feed esc [ %r m" % code) -- cgit v1.2.3