Browse Source

few minor fixes after the new color handling

pull/208/head
Eugenio Parodi 1 year ago
parent
commit
c06d463f6a
  1. 4
      TermTk/TTkCore/color.py
  2. 13
      TermTk/TTkWidgets/TTkTerminal/terminalview.py
  3. 2
      tests/t.generic/test.generic.008.class.override.03.py
  4. 29
      tests/t.generic/test.generic.012.boolean.01.py

4
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 (

13
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: <ESC>{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)

2
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__}"

29
tests/t.generic/test.generic.012.boolean.01.py

@ -0,0 +1,29 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com>
#
# 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}")
Loading…
Cancel
Save