mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
simplify
This commit is contained in:
@@ -300,8 +300,6 @@ ANSI_SEQUENCES_KEYS: Mapping[str, Tuple[Keys, ...]] = {
|
|||||||
"\x1b[1;8y": (Keys.Escape, Keys.ControlShift9),
|
"\x1b[1;8y": (Keys.Escape, Keys.ControlShift9),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
|
||||||
TERMINAL_MODES_ANSI_SEQUENCES: Mapping[str, str] = {
|
SYNC_START = "\x1b[?2026h"
|
||||||
"sync_start": "\x1b[?2026h",
|
SYNC_END = "\x1b[?2026l"
|
||||||
"sync_stop": "\x1b[?2026l",
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -254,12 +254,15 @@ class Compositor:
|
|||||||
if screen not in self._dirty_regions:
|
if screen not in self._dirty_regions:
|
||||||
crop_screen = screen.intersection
|
crop_screen = screen.intersection
|
||||||
changes = map.items() ^ old_map.items()
|
changes = map.items() ^ old_map.items()
|
||||||
self._dirty_regions.update(
|
regions = {
|
||||||
[
|
region
|
||||||
|
for region in (
|
||||||
crop_screen(map_geometry.visible_region)
|
crop_screen(map_geometry.visible_region)
|
||||||
for _, map_geometry in changes
|
for _, map_geometry in changes
|
||||||
]
|
)
|
||||||
)
|
if region
|
||||||
|
}
|
||||||
|
self._dirty_regions.update(regions)
|
||||||
|
|
||||||
return ReflowResult(
|
return ReflowResult(
|
||||||
hidden=hidden_widgets,
|
hidden=hidden_widgets,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from typing import (
|
|||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ._ansi_sequences import TERMINAL_MODES_ANSI_SEQUENCES
|
from ._ansi_sequences import SYNC_START, SYNC_END
|
||||||
|
|
||||||
if sys.version_info >= (3, 8):
|
if sys.version_info >= (3, 8):
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
@@ -897,10 +897,12 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
console = self.console
|
console = self.console
|
||||||
self._begin_update()
|
self._begin_update()
|
||||||
try:
|
try:
|
||||||
console.print(renderable)
|
try:
|
||||||
except Exception as error:
|
console.print(renderable)
|
||||||
self.on_exception(error)
|
except Exception as error:
|
||||||
self._end_update()
|
self.on_exception(error)
|
||||||
|
finally:
|
||||||
|
self._end_update()
|
||||||
console.file.flush()
|
console.file.flush()
|
||||||
|
|
||||||
def measure(self, renderable: RenderableType, max_width=100_000) -> int:
|
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(
|
def handle_terminal_supports_synchronized_output(
|
||||||
self, message: messages.TerminalSupportsSynchronizedOutput
|
self, message: messages.TerminalSupportsSynchronizedOutput
|
||||||
) -> None:
|
) -> None:
|
||||||
log("SynchronizedOutput mode is supported by this terminal")
|
log("[b green]SynchronizedOutput mode is supported")
|
||||||
self._sync_available = True
|
self._sync_available = True
|
||||||
|
|
||||||
def _begin_update(self) -> None:
|
def _begin_update(self) -> None:
|
||||||
if self._sync_available:
|
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:
|
def _end_update(self) -> None:
|
||||||
if self._sync_available:
|
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
|
_uvloop_init_done: bool = False
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from rich.style import Style
|
|||||||
|
|
||||||
from . import events, messages, errors
|
from . import events, messages, errors
|
||||||
|
|
||||||
from .color import Color
|
|
||||||
from .geometry import Offset, Region, Size
|
from .geometry import Offset, Region, Size
|
||||||
from ._compositor import Compositor, MapGeometry
|
from ._compositor import Compositor, MapGeometry
|
||||||
from .reactive import Reactive
|
from .reactive import Reactive
|
||||||
|
|||||||
Reference in New Issue
Block a user