Add arguments to get the first and last line of text for launch command

This commit is contained in:
pagedown 2022-02-05 20:02:24 +08:00
parent ced61096df
commit e22546c56a
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB
3 changed files with 15 additions and 1 deletions

View File

@ -99,6 +99,10 @@ Detailed list of changes
- A new action :ac:`scroll_prompt_to_bottom` to move the current prompt - 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`) 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 <launch>` command to be used for pager positioning.
(:iss:`4462`)
0.24.2 [2022-02-03] 0.24.2 [2022-02-03]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -95,6 +95,12 @@ the command line:
``@cursor-y`` ``@cursor-y``
replaced by the current cursor y position with 1 being the topmost cell 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:: For example::

View File

@ -397,7 +397,7 @@ def launch(
elif x == '@line-count': elif x == '@line-count':
if 'lines' in pipe_data: if 'lines' in pipe_data:
x = str(pipe_data['lines']) 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: if active is not None:
screen = active.screen screen = active.screen
if x == '@scrolled-by': if x == '@scrolled-by':
@ -406,6 +406,10 @@ def launch(
x = str(screen.cursor.x + 1) x = str(screen.cursor.x + 1)
elif x == '@cursor-y': elif x == '@cursor-y':
x = str(screen.cursor.y + 1) 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) final_cmd.append(x)
exe = which(final_cmd[0]) exe = which(final_cmd[0])
if exe: if exe: