From e22546c56a281c1c79ac76c196e69b9db2cb61f1 Mon Sep 17 00:00:00 2001 From: pagedown Date: Sat, 5 Feb 2022 20:02:24 +0800 Subject: [PATCH] Add arguments to get the first and last line of text for launch command --- docs/changelog.rst | 4 ++++ docs/launch.rst | 6 ++++++ kitty/launch.py | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 17d75b4ae..00f1fe932 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -99,6 +99,10 @@ Detailed list of changes - A new action :ac:`scroll_prompt_to_bottom` to move the current prompt to the bottom, filling in the window from the scrollback (:pull:`4634`) +- Add two special arguments ``@first-line-on-screen`` and ``@first-line-on-screen`` + for the :doc:`launch ` command to be used for pager positioning. + (:iss:`4462`) + 0.24.2 [2022-02-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/launch.rst b/docs/launch.rst index bdda8c9b4..47f6d65b5 100644 --- a/docs/launch.rst +++ b/docs/launch.rst @@ -95,6 +95,12 @@ the command line: ``@cursor-y`` replaced by the current cursor y position with 1 being the topmost cell +``@first-line-on-screen`` + replaced by the first line on screen. Can be used for pager positioning. + +``@last-line-on-screen`` + replaced by the last line on screen. Can be used for pager positioning. + For example:: diff --git a/kitty/launch.py b/kitty/launch.py index f8b4ee932..57284a424 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -397,7 +397,7 @@ def launch( elif x == '@line-count': if 'lines' in pipe_data: x = str(pipe_data['lines']) - elif x in ('@cursor-x', '@cursor-y', '@scrolled-by'): + elif x in ('@cursor-x', '@cursor-y', '@scrolled-by', '@first-line-on-screen', '@last-line-on-screen'): if active is not None: screen = active.screen if x == '@scrolled-by': @@ -406,6 +406,10 @@ def launch( x = str(screen.cursor.x + 1) elif x == '@cursor-y': x = str(screen.cursor.y + 1) + elif x == '@first-line-on-screen': + x = str(screen.visual_line(0) or '') + elif x == '@last-line-on-screen': + x = str(screen.visual_line(screen.lines - 1) or '') final_cmd.append(x) exe = which(final_cmd[0]) if exe: