From 95c4e26b2484d881ef24c09d5e094734c160f78c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 6 Mar 2022 21:52:59 +0530 Subject: [PATCH] macOS: When using Apple's less as the pager for viewing scrollback strip out OSC codes as Apple's less cant parse them Fixes #4788 --- docs/changelog.rst | 4 ++++ kitty/boss.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 794f00bcf..565336b26 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -75,6 +75,10 @@ command. Detailed list of changes ------------------------------------- +0.25.0 [future] + +- macOS: When using Apple's less as the pager for viewing scrollback strip out OSC codes as Apple's less cant parse them (:iss:`4788`) + 0.24.4 [2022-03-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index 3b181a9e9..96a8d449b 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1313,6 +1313,8 @@ class Boss: s.close() def display_scrollback(self, window: Window, data: Union[bytes, str], input_line_number: int = 0, title: str = '', report_cursor: bool = True) -> None: + import shutil + def prepare_arg(x: str) -> str: x = x.replace('INPUT_LINE_NUMBER', str(input_line_number)) x = x.replace('CURSOR_LINE', str(window.screen.cursor.y + 1) if report_cursor else '0') @@ -1328,6 +1330,10 @@ class Boss: tab = self.active_tab if tab is not None: bdata = data.encode('utf-8') if isinstance(data, str) else data + if is_macos and shutil.which(cmd[0]) == '/usr/bin/less': + # the system less on macOS barfs up OSC codes, so sanitize them ourselves + bdata = re.sub(br'\x1b\].*?\x1b\\', b'', bdata) + tab.new_special_window( SpecialWindow(cmd, bdata, title or _('History'), overlay_for=window.id, cwd=window.cwd_of_child), copy_colors_from=self.active_window