This commit is contained in:
Will McGugan
2023-04-07 08:44:52 +01:00
committed by GitHub
parent 976bd2f5c2
commit c3424b0224
2 changed files with 17 additions and 10 deletions

View File

@@ -14,7 +14,15 @@ without having to render the entire screen.
from __future__ import annotations
from operator import itemgetter
from typing import TYPE_CHECKING, Callable, Iterable, NamedTuple, cast
from typing import (
TYPE_CHECKING,
Callable,
Iterable,
Mapping,
NamedTuple,
Sequence,
cast,
)
import rich.repr
from rich.console import Console, ConsoleOptions, RenderableType, RenderResult
@@ -105,7 +113,7 @@ class ChopsUpdate:
def __init__(
self,
chops: list[dict[int, Strip | None]],
chops: Sequence[Mapping[int, Strip | None]],
spans: list[tuple[int, int, int]],
chop_ends: list[list[int]],
) -> None:
@@ -876,7 +884,7 @@ class Compositor:
self,
crop: Region,
is_rendered_line: Callable[[int], bool],
) -> list[dict[int, Strip | None]]:
) -> Sequence[Mapping[int, Strip | None]]:
"""Render update 'chops'.
Args:
@@ -907,10 +915,8 @@ class Compositor:
chops_line = chops[y]
first_cut, last_cut = render_region.column_span
cuts_line = cuts[y]
final_cuts = [
cut for cut in cuts_line if (last_cut >= cut >= first_cut)
]
final_cuts = [cut for cut in cuts[y] if (last_cut >= cut >= first_cut)]
if len(final_cuts) <= 2:
# Two cuts, which means the entire line
cut_strips = [strip]
@@ -920,8 +926,9 @@ class Compositor:
cut_strips = strip.divide(relative_cuts)
# Since we are painting front to back, the first segments for a cut "wins"
get_chops_line = chops_line.get
for cut, strip in zip(final_cuts, cut_strips):
if chops_line[cut] is None:
if get_chops_line(cut) is None:
chops_line[cut] = strip
return chops

View File

@@ -1,7 +1,7 @@
from __future__ import annotations
from itertools import chain
from typing import Iterable, Iterator
from typing import Iterable, Iterator, Sequence
import rich.repr
from rich.cells import cell_len, set_cell_size
@@ -348,7 +348,7 @@ class Strip:
self._crop_cache[cache_key] = strip
return strip
def divide(self, cuts: Iterable[int]) -> list[Strip]:
def divide(self, cuts: Iterable[int]) -> Sequence[Strip]:
"""Divide the strip in to multiple smaller strips by cutting at given (cell) indices.
Args: