@@ -444,7 +444,11 @@ def size(self) -> Size:
444444 Returns:
445445 Size: Size of the terminal
446446 """
447- return Size (* self .console .size )
447+ if self ._driver is not None and self ._driver ._size is not None :
448+ width , height = self ._driver ._size
449+ else :
450+ width , height = self .console .size
451+ return Size (width , height )
448452
449453 @property
450454 def log (self ) -> Logger :
@@ -526,10 +530,11 @@ def export_screenshot(self, *, title: str | None = None) -> str:
526530 to use app title. Defaults to None.
527531
528532 """
529-
533+ assert self ._driver is not None , "App must be running"
534+ width , height = self .size
530535 console = Console (
531- width = self . console . width ,
532- height = self . console . height ,
536+ width = width ,
537+ height = height ,
533538 file = io .StringIO (),
534539 force_terminal = True ,
535540 color_system = "truecolor" ,
@@ -669,12 +674,15 @@ async def run_async(
669674 self ,
670675 * ,
671676 headless : bool = False ,
677+ size : tuple [int , int ] | None = None ,
672678 auto_pilot : AutopilotCallbackType | None = None ,
673679 ) -> ReturnType | None :
674680 """Run the app asynchronously.
675681
676682 Args:
677683 headless (bool, optional): Run in headless mode (no output). Defaults to False.
684+ size (tuple[int, int] | None, optional): Force terminal size to `(WIDTH, HEIGHT)`,
685+ or None to auto-detect. Defaults to None.
678686 auto_pilot (AutopilotCallbackType): An auto pilot coroutine.
679687
680688 Returns:
@@ -707,6 +715,7 @@ async def run_auto_pilot(
707715 await app ._process_messages (
708716 ready_callback = None if auto_pilot is None else app_ready ,
709717 headless = headless ,
718+ terminal_size = size ,
710719 )
711720 finally :
712721 if auto_pilot_task is not None :
@@ -719,12 +728,15 @@ def run(
719728 self ,
720729 * ,
721730 headless : bool = False ,
731+ size : tuple [int , int ] | None = None ,
722732 auto_pilot : AutopilotCallbackType | None = None ,
723733 ) -> ReturnType | None :
724734 """Run the app.
725735
726736 Args:
727737 headless (bool, optional): Run in headless mode (no output). Defaults to False.
738+ size (tuple[int, int] | None, optional): Force terminal size to `(WIDTH, HEIGHT)`,
739+ or None to auto-detect. Defaults to None.
728740 auto_pilot (AutopilotCallbackType): An auto pilot coroutine.
729741
730742 Returns:
@@ -735,6 +747,7 @@ async def run_app() -> None:
735747 """Run the app."""
736748 await self .run_async (
737749 headless = headless ,
750+ size = size ,
738751 auto_pilot = auto_pilot ,
739752 )
740753
@@ -1072,7 +1085,10 @@ def _print_error_renderables(self) -> None:
10721085 self ._exit_renderables .clear ()
10731086
10741087 async def _process_messages (
1075- self , ready_callback : CallbackType | None = None , headless : bool = False
1088+ self ,
1089+ ready_callback : CallbackType | None = None ,
1090+ headless : bool = False ,
1091+ terminal_size : tuple [int , int ] | None = None ,
10761092 ) -> None :
10771093 self ._set_active ()
10781094
@@ -1161,7 +1177,7 @@ async def run_process_messages():
11611177 "type[Driver]" ,
11621178 HeadlessDriver if headless else self .driver_class ,
11631179 )
1164- driver = self ._driver = driver_class (self .console , self )
1180+ driver = self ._driver = driver_class (self .console , self , size = terminal_size )
11651181
11661182 driver .start_application_mode ()
11671183 try :
0 commit comments