From c06d463f6a2e2e107f0bd335c5a8051c894ac771 Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Wed, 20 Nov 2024 18:54:11 +0000 Subject: [PATCH] few minor fixes after the new color handling --- TermTk/TTkCore/color.py | 4 +-- TermTk/TTkWidgets/TTkTerminal/terminalview.py | 13 +++++++-- .../test.generic.008.class.override.03.py | 2 +- .../t.generic/test.generic.012.boolean.01.py | 29 +++++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100755 tests/t.generic/test.generic.012.boolean.01.py diff --git a/TermTk/TTkCore/color.py b/TermTk/TTkCore/color.py index 4917860b..da6c585b 100644 --- a/TermTk/TTkCore/color.py +++ b/TermTk/TTkCore/color.py @@ -263,7 +263,7 @@ class _TTkColor_mod(_TTkColor): ) -> None: self._mod = mod super().__init__(**kwargs) - self._clean = self._clean or mod + self._clean = self._clean and not mod def bold(self) -> bool: return self._mod & TTkTermColor.BOLD @@ -363,7 +363,7 @@ class _TTkColor_mod_link(_TTkColor_mod): ) -> None: self._link = link super().__init__(**kwargs) - self._clean = self._clean or link + self._clean = self._clean and not link def colorType(self): return ( diff --git a/TermTk/TTkWidgets/TTkTerminal/terminalview.py b/TermTk/TTkWidgets/TTkTerminal/terminalview.py index 4eec8983..e925e3cb 100644 --- a/TermTk/TTkWidgets/TTkTerminal/terminalview.py +++ b/TermTk/TTkWidgets/TTkTerminal/terminalview.py @@ -27,7 +27,7 @@ import re from dataclasses import dataclass from TermTk.TTkCore.canvas import TTkCanvas -from TermTk.TTkCore.color import TTkColor +from TermTk.TTkCore.color import TTkColor, _TTkColor, _TTkColor_mod, _TTkColor_mod_link from TermTk.TTkCore.log import TTkLog from TermTk.TTkCore.constant import TTkK from TermTk.TTkCore.string import TTkString @@ -354,6 +354,9 @@ class TTkTerminalView(TTkAbstractScrollView, _TTkTerminal_CSI_DEC): # CSI Color Functions # CSI Pm ; Pm ; ... m ################################################ + # TODO: Rework this routine to avoid the use + # of the internal color sub classes + ################################################ elif ((m := TTkTerminalView.re_CURSOR.match(slice)) and (mg := m.groups()) and mg[-1] == 'm' ): @@ -367,7 +370,7 @@ class TTkTerminalView(TTkAbstractScrollView, _TTkTerminal_CSI_DEC): color = self._screen_current.color() fg = color._fg bg = color._bg - mod = color._mod + mod = color._mod if hasattr(color,'_mod') else 0 clean = False while values: @@ -407,7 +410,11 @@ class TTkTerminalView(TTkAbstractScrollView, _TTkTerminal_CSI_DEC): mod &= _sgr else: _termLog.warn(f"Unhandled color: {slice}") - color = TTkColor(fg=fg, bg=bg, mod=mod, clean=clean) + if mod: + color = _TTkColor_mod(fg=fg, bg=bg, mod=mod, clean=clean) + else: + color = _TTkColor(fg=fg, bg=bg, clean=clean) + # color = TTkColor(fg=fg, bg=bg, mod=mod, clean=clean) self._screen_alt.setColor(color) self._screen_normal.setColor(color) diff --git a/tests/t.generic/test.generic.008.class.override.03.py b/tests/t.generic/test.generic.008.class.override.03.py index 961e938d..ea963a7a 100755 --- a/tests/t.generic/test.generic.008.class.override.03.py +++ b/tests/t.generic/test.generic.008.class.override.03.py @@ -27,7 +27,7 @@ class A(): self.a = a self.b = b - def __str__(self): return f"a={self.a} {type(self).__name__} {type(other).__name__}, b={self.b}" + def __str__(self): return f"a={self.a}, b={self.b}" def __sub__(self, other): return f"A( ). sub {type(self).__name__} {type(other).__name__}" def __or__( self, other): return f"A( ). or {type(self).__name__} {type(other).__name__}" def __ror__(self, other): return f"A( ).R-or {type(self).__name__} {type(other).__name__}" diff --git a/tests/t.generic/test.generic.012.boolean.01.py b/tests/t.generic/test.generic.012.boolean.01.py new file mode 100755 index 00000000..9de7239d --- /dev/null +++ b/tests/t.generic/test.generic.012.boolean.01.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + +for i in range(0xF): + a,b,c,d = i&1,i&1<<1,i&1<<2,i&1<<3 + print(f"{a} {b} {c} {d} = {a or not (b or c or d)} -> {a or not (b or c) and not d}")