File size: 1,322 Bytes
5b76e0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from __future__ import annotations
import asyncio
from ..driver import Driver
from ..geometry import Size
from .. import events
class HeadlessDriver(Driver):
"""A do-nothing driver for testing."""
def _get_terminal_size(self) -> tuple[int, int]:
width: int | None = 80
height: int | None = 25
import shutil
try:
width, height = shutil.get_terminal_size()
except (AttributeError, ValueError, OSError):
try:
width, height = shutil.get_terminal_size()
except (AttributeError, ValueError, OSError):
pass
width = width or 80
height = height or 25
return width, height
def start_application_mode(self) -> None:
loop = asyncio.get_running_loop()
def send_size_event():
terminal_size = self._get_terminal_size()
width, height = terminal_size
textual_size = Size(width, height)
event = events.Resize(self._target, textual_size, textual_size)
asyncio.run_coroutine_threadsafe(
self._target.post_message(event),
loop=loop,
)
send_size_event()
def disable_input(self) -> None:
pass
def stop_application_mode(self) -> None:
pass
|