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
This commit is contained in:
Kovid Goyal 2022-03-06 21:52:59 +05:30
parent 795953a341
commit 95c4e26b24
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 0 deletions

View File

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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