Add a default mapping for searching the scrollback

Opens the scrollback pager in search mode. Particularly useful for
newbies on macOS that are used to using cmd+f to trigger search mode.

If there is a current selection, it is automatically searched for.
This commit is contained in:
Kovid Goyal
2025-12-01 08:10:07 +05:30
parent 9b6b9733b9
commit 20b39ee163
10 changed files with 54 additions and 6 deletions

View File

@@ -2101,11 +2101,29 @@ class Window:
# actions {{{
@ac('cp', 'Show scrollback in a pager like less')
def show_scrollback(self) -> None:
def show_scrollback(self) -> Optional['Window']:
text = self.as_text(as_ansi=True, add_history=True, add_wrap_markers=True)
data = self.pipe_data(text, has_wrap_markers=True)
cursor_on_screen = self.screen.scrolled_by < self.screen.lines - self.screen.cursor.y
get_boss().display_scrollback(self, data['text'], data['input_line_number'], report_cursor=cursor_on_screen)
return get_boss().display_scrollback(self, data['text'], data['input_line_number'], report_cursor=cursor_on_screen)
@ac('cp', '''
Search scrollback in a pager like less. If there is selected text, it is automatically searched for.
Note that this assumes that pressing the / key triggers search mode in the page configured as the
scrollback pager.
''')
def search_scrollback(self) -> None:
text = self.text_for_selection()
w = self.show_scrollback()
if w is not None:
w.send_key('/')
if text:
btext = text.encode()
sanitized = replace_c0_codes_except_nl_space_tab(btext)
if not w.screen.in_bracketed_paste_mode:
sanitized = sanitized.replace(b'\n', b'\x1bE')
w.screen.paste_bytes(sanitized)
w.send_key('enter')
def show_cmd_output(self, which: CommandOutput, title: str = 'Command output', as_ansi: bool = True, add_wrap_markers: bool = True) -> None:
text = self.cmd_output(which, as_ansi=as_ansi, add_wrap_markers=add_wrap_markers)