This commit is contained in:
Will McGugan
2022-05-27 15:17:16 +01:00
parent b806779267
commit d45b044888
4 changed files with 20 additions and 18 deletions

View File

@@ -300,8 +300,6 @@ ANSI_SEQUENCES_KEYS: Mapping[str, Tuple[Keys, ...]] = {
"\x1b[1;8y": (Keys.Escape, Keys.ControlShift9),
}
TERMINAL_MODES_ANSI_SEQUENCES: Mapping[str, str] = {
"sync_start": "\x1b[?2026h",
"sync_stop": "\x1b[?2026l",
}
# https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
SYNC_START = "\x1b[?2026h"
SYNC_END = "\x1b[?2026l"

View File

@@ -254,12 +254,15 @@ class Compositor:
if screen not in self._dirty_regions:
crop_screen = screen.intersection
changes = map.items() ^ old_map.items()
self._dirty_regions.update(
[
regions = {
region
for region in (
crop_screen(map_geometry.visible_region)
for _, map_geometry in changes
]
)
)
if region
}
self._dirty_regions.update(regions)
return ReflowResult(
hidden=hidden_widgets,

View File

@@ -22,7 +22,7 @@ from typing import (
TYPE_CHECKING,
)
from ._ansi_sequences import TERMINAL_MODES_ANSI_SEQUENCES
from ._ansi_sequences import SYNC_START, SYNC_END
if sys.version_info >= (3, 8):
from typing import Literal
@@ -897,10 +897,12 @@ class App(Generic[ReturnType], DOMNode):
console = self.console
self._begin_update()
try:
console.print(renderable)
except Exception as error:
self.on_exception(error)
self._end_update()
try:
console.print(renderable)
except Exception as error:
self.on_exception(error)
finally:
self._end_update()
console.file.flush()
def measure(self, renderable: RenderableType, max_width=100_000) -> int:
@@ -1103,16 +1105,16 @@ class App(Generic[ReturnType], DOMNode):
def handle_terminal_supports_synchronized_output(
self, message: messages.TerminalSupportsSynchronizedOutput
) -> None:
log("SynchronizedOutput mode is supported by this terminal")
log("[b green]SynchronizedOutput mode is supported")
self._sync_available = True
def _begin_update(self) -> None:
if self._sync_available:
self.console.file.write(TERMINAL_MODES_ANSI_SEQUENCES["sync_start"])
self.console.file.write(SYNC_START)
def _end_update(self) -> None:
if self._sync_available:
self.console.file.write(TERMINAL_MODES_ANSI_SEQUENCES["sync_stop"])
self.console.file.write(SYNC_END)
_uvloop_init_done: bool = False

View File

@@ -9,7 +9,6 @@ from rich.style import Style
from . import events, messages, errors
from .color import Color
from .geometry import Offset, Region, Size
from ._compositor import Compositor, MapGeometry
from .reactive import Reactive