Pass key events mapped to scroll actions to the program running in the terminal when the terminal is in alternate screen mode

Fixes #5839
This commit is contained in:
Kovid Goyal 2022-12-30 08:54:31 +05:30
parent c76bbeabd6
commit 4f9ed6546a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 42 additions and 17 deletions

View File

@ -27,6 +27,11 @@ Browse scrollback in less :sc:`show_scrollback`
Browse last cmd output :sc:`show_last_command_output` (see :ref:`shell_integration`)
========================= =======================
The scroll actions only take effect when the terminal is in the main screen.
When the alternate screen is active (for example when using a full screen
program like an editor) the key events are instead passed to program running in the
terminal.
Tabs
~~~~~~~~~~~

View File

@ -53,6 +53,8 @@ Detailed list of changes
- Allow using the cwd of the original process for :option:`launch --cwd` (:iss:`5672`)
- Pass key events mapped to scroll actions to the program running in the terminal when the terminal is in alternate screen mode (:iss:`5839`)
- Implement :ref:`edit-in-kitty <edit_file>` using the new ``kitty-tool`` static executable (:iss:`5546`, :iss:`5630`)
- Add an option :opt:`background_tint_gaps` to control background image tinting for window gaps (:iss:`5596`)

View File

@ -1517,35 +1517,47 @@ class Window:
def clear_selection(self) -> None:
self.screen.clear_selection()
@ac('sc', 'Scroll up by one line')
def scroll_line_up(self) -> None:
@ac('sc', 'Scroll up by one line when in main screen')
def scroll_line_up(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_LINE, True)
return None
return True
@ac('sc', 'Scroll down by one line')
def scroll_line_down(self) -> None:
@ac('sc', 'Scroll down by one line when in main screen')
def scroll_line_down(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_LINE, False)
return None
return True
@ac('sc', 'Scroll up by one page')
def scroll_page_up(self) -> None:
@ac('sc', 'Scroll up by one page when in main screen')
def scroll_page_up(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_PAGE, True)
return None
return True
@ac('sc', 'Scroll down by one page')
def scroll_page_down(self) -> None:
@ac('sc', 'Scroll down by one page when in main screen')
def scroll_page_down(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_PAGE, False)
return None
return True
@ac('sc', 'Scroll to the top of the scrollback buffer')
def scroll_home(self) -> None:
@ac('sc', 'Scroll to the top of the scrollback buffer when in main screen')
def scroll_home(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_FULL, True)
return None
return True
@ac('sc', 'Scroll to the bottom of the scrollback buffer')
def scroll_end(self) -> None:
@ac('sc', 'Scroll to the bottom of the scrollback buffer when in main screen')
def scroll_end(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll(SCROLL_FULL, False)
return None
return True
@ac('sc', '''
Scroll to the previous/next shell command prompt
@ -1559,23 +1571,29 @@ class Window:
map ctrl+n scroll_to_prompt 1 # jump to next
map ctrl+o scroll_to_prompt 0 # jump to last visited
''')
def scroll_to_prompt(self, num_of_prompts: int = -1) -> None:
def scroll_to_prompt(self, num_of_prompts: int = -1) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll_to_prompt(num_of_prompts)
return None
return True
@ac('sc', 'Scroll prompt to the top of the screen, filling screen with empty lines')
def scroll_prompt_to_top(self, clear_scrollback: bool = False) -> None:
@ac('sc', 'Scroll prompt to the top of the screen, filling screen with empty lines, when in main screen')
def scroll_prompt_to_top(self, clear_scrollback: bool = False) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll_until_cursor_prompt()
if clear_scrollback:
self.screen.clear_scrollback()
elif self.screen.scrolled_by > 0:
self.screen.scroll(SCROLL_FULL, False)
return None
return True
@ac('sc', 'Scroll prompt to the bottom of the screen, filling in extra lines from the scrollback buffer')
def scroll_prompt_to_bottom(self) -> None:
@ac('sc', 'Scroll prompt to the bottom of the screen, filling in extra lines from the scrollback buffer, when in main screen')
def scroll_prompt_to_bottom(self) -> Optional[bool]:
if self.screen.is_main_linebuf():
self.screen.scroll_prompt_to_bottom()
return None
return True
@ac('mk', 'Toggle the current marker on/off')
def toggle_marker(self, ftype: str, spec: Union[str, Tuple[Tuple[int, str], ...]], flags: int) -> None: