From 9caf0cf5363e6e4081a98f01e62d9dbcda3726f2 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 25 Jan 2023 13:26:10 +0100 Subject: [PATCH 1/3] don't request sync on macOS app --- src/textual/drivers/linux_driver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/textual/drivers/linux_driver.py b/src/textual/drivers/linux_driver.py index f5f90ae0bf..bbdfbd5641 100644 --- a/src/textual/drivers/linux_driver.py +++ b/src/textual/drivers/linux_driver.py @@ -146,8 +146,9 @@ def on_terminal_resize(signum, stack) -> None: self._enable_bracketed_paste() def _request_terminal_sync_mode_support(self): - self.console.file.write("\033[?2026$p") - self.console.file.flush() + if self.console._environ.get("TERM", "") != "iTerm.app": + self.console.file.write("\033[?2026$p") + self.console.file.flush() @classmethod def _patch_lflag(cls, attrs: int) -> int: From 15af0cd2c62ae866b83ddef312783d2b12dca402 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 25 Jan 2023 13:28:37 +0100 Subject: [PATCH 2/3] wrong env var --- src/textual/drivers/linux_driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/drivers/linux_driver.py b/src/textual/drivers/linux_driver.py index bbdfbd5641..35812d8569 100644 --- a/src/textual/drivers/linux_driver.py +++ b/src/textual/drivers/linux_driver.py @@ -146,7 +146,7 @@ def on_terminal_resize(signum, stack) -> None: self._enable_bracketed_paste() def _request_terminal_sync_mode_support(self): - if self.console._environ.get("TERM", "") != "iTerm.app": + if self.console._environ.get("TERM_PROGRAM", "") != "Apple_Terminal": self.console.file.write("\033[?2026$p") self.console.file.flush() From a292086a622f7cebc2d50ded9c550aa61e75a655 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 25 Jan 2023 13:39:24 +0100 Subject: [PATCH 3/3] comment and docstring --- src/textual/drivers/linux_driver.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/textual/drivers/linux_driver.py b/src/textual/drivers/linux_driver.py index 35812d8569..2d1b5e1a00 100644 --- a/src/textual/drivers/linux_driver.py +++ b/src/textual/drivers/linux_driver.py @@ -145,7 +145,11 @@ def on_terminal_resize(signum, stack) -> None: self._request_terminal_sync_mode_support() self._enable_bracketed_paste() - def _request_terminal_sync_mode_support(self): + def _request_terminal_sync_mode_support(self) -> None: + """Writes an escape sequence to query the terminal support for the sync protocol.""" + # Terminals should ignore this sequence if not supported. + # Apple terminal doesn't, and writes a single 'p' in to the terminal, + # so we will make a special case for Apple terminal (which doesn't support sync anyway). if self.console._environ.get("TERM_PROGRAM", "") != "Apple_Terminal": self.console.file.write("\033[?2026$p") self.console.file.flush()