diff --git a/docs/changelog.rst b/docs/changelog.rst index d70630261..436ac3025 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -21,6 +21,10 @@ Changelog - Implement changing the font size for individual top level (OS) windows (:iss:`408`) +- When viewing the scrollback in less using :sc:`show_scrollback` and kitty + is currently scrolled, position the scrollback in less to match kitty's + scroll position. (:iss:`148`) + - ssh kitten: Support all SSH options. It can now be aliased directly to ssh for convenience. (:pull:`591`) diff --git a/kitty/boss.py b/kitty/boss.py index 2d882226d..06bd03e74 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -528,12 +528,12 @@ class Boss: for window_id in tuple(w.id for w in self.window_id_map.values() if getattr(w, 'os_window_id', None) == os_window_id): self.window_id_map.pop(window_id, None) - def display_scrollback(self, window, data): + def display_scrollback(self, window, data, cmd): tab = self.active_tab if tab is not None and window.overlay_for is None: tab.new_special_window( SpecialWindow( - self.opts.scrollback_pager, data, _('History'), overlay_for=window.id)) + cmd, data, _('History'), overlay_for=window.id)) def edit_config_file(self, *a): confpath = prepare_config_file_for_editing() diff --git a/kitty/config_data.py b/kitty/config_data.py index 54e54be59..69b82b50d 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -275,10 +275,12 @@ o('scrollback_lines', 2000, option_type=positive_int, long_text=_(''' Number of lines of history to keep in memory for scrolling back. Memory is allocated on demand.''')) -o('scrollback_pager', 'less +G -R', option_type=to_cmdline, long_text=_(''' +o('scrollback_pager', 'less --RAW-CONTROL-CHARS +INPUT_LINE_NUMBER', option_type=to_cmdline, long_text=_(''' Program with which to view scrollback in a new window. The scrollback buffer is passed as STDIN to this program. If you change it, make sure the program you -use can handle ANSI escape sequences for colors and text formatting.''')) +use can handle ANSI escape sequences for colors and text formatting. +INPUT_LINE_NUMBER in the command line above will be replaced by an integer +representing which line should be at the top of the screen.''')) o('wheel_scroll_multiplier', 5.0, long_text=_(''' Modify the amount scrolled by the mouse wheel or touchpad. Use diff --git a/kitty/window.py b/kitty/window.py index 91b0bace0..f7e229dce 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -418,7 +418,12 @@ class Window: # actions {{{ def show_scrollback(self): - get_boss().display_scrollback(self, self.as_text(as_ansi=True, add_history=True).encode('utf-8')) + data = self.as_text(as_ansi=True, add_history=True, add_wrap_markers=True) + data = data.replace('\r\n', '\n').replace('\r', '\n') + lines = data.count('\n') + input_line_number = (lines - (self.screen.lines - 1) - self.screen.scrolled_by) + cmd = [x.replace('INPUT_LINE_NUMBER', str(input_line_number)) for x in self.opts.scrollback_pager] + get_boss().display_scrollback(self, data, cmd) def paste(self, text): if text and not self.destroyed: