more PR fixes

This commit is contained in:
Nitzan Shaked
2023-01-03 09:36:25 +02:00
parent c1a90c25a1
commit b78ca2bad2
2 changed files with 8 additions and 8 deletions

View File

@@ -7,7 +7,6 @@ Functions and classes to manage terminal geometry (anything involving coordinate
from __future__ import annotations
from functools import lru_cache
import math
from operator import attrgetter, itemgetter
from typing import Any, Collection, NamedTuple, Tuple, TypeVar, Union, cast
@@ -130,7 +129,7 @@ class Offset(NamedTuple):
"""
x1, y1 = self
x2, y2 = other
distance = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
distance: float = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) ** 0.5
return distance
@@ -218,6 +217,8 @@ class Size(NamedTuple):
def __contains__(self, other: Any) -> bool:
try:
x: int
y: int
x, y = other
except Exception:
raise TypeError(

View File

@@ -65,21 +65,20 @@ class TextOpacity:
for text, style, control in cast(
Iterable[tuple[str, Style, object]], segments
):
assert style is not None
invisible_style = _from_color(bgcolor=style.bgcolor)
yield _Segment(cell_len(text) * " ", invisible_style)
else:
for segment in segments:
text, maybe_style, control = segment
if not maybe_style:
text, style, control = cast(tuple[str, Style, object], segment)
if not style:
yield segment
continue
color = maybe_style.color
bgcolor = maybe_style.bgcolor
color = style.color
bgcolor = style.bgcolor
if color and color.triplet and bgcolor and bgcolor.triplet:
color_style = _get_blended_style_cached(bgcolor, color, opacity)
yield _Segment(text, maybe_style + color_style)
yield _Segment(text, style + color_style)
else:
yield segment