mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
more PR fixes
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user