mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 10:12:17 +02:00
Remote control: allow scrolling to prev/next prompt
This commit is contained in:
@@ -16,7 +16,7 @@ class ScrollWindow(RemoteCommand):
|
||||
amount+/list.scroll_amount: The amount to scroll, a two item list with the first item being \
|
||||
either a number or the keywords, start and end. \
|
||||
And the second item being either 'p' for pages or 'l' for lines or 'u'
|
||||
for unscrolling by lines.
|
||||
for unscrolling by lines, or 'r' for scrolling ot prompt.
|
||||
match/str: The window to scroll
|
||||
'''
|
||||
|
||||
@@ -24,9 +24,13 @@ class ScrollWindow(RemoteCommand):
|
||||
desc = (
|
||||
'Scroll the specified windows, if no window is specified, scroll the window this command is run inside.'
|
||||
' :italic:`SCROLL_AMOUNT` can be either the keywords :code:`start` or :code:`end` or an'
|
||||
' argument of the form :italic:`<number>[unit][+-]`. For example, :code:`30` will scroll down 30 lines, :code:`2p-`'
|
||||
' will scroll up 2 pages and :code:`0.5p`will scroll down half page. :code:`3u` will *unscroll* by 3 lines, which means that 3 lines will move from the'
|
||||
' scrollback buffer onto the top of the screen.'
|
||||
' argument of the form :italic:`<number>[unit][+-]`. :code:`unit` can be :code:`l` for lines, :code:`p` for pages,'
|
||||
' :code:`u` for unscroll and :code:`r` for scroll to prompt. If unspecifed, :code:`l` is the default.'
|
||||
' For example, :code:`30` will scroll down 30 lines, :code:`2p-`'
|
||||
' will scroll up 2 pages and :code:`0.5p` will scroll down half page.'
|
||||
' :code:`3u` will *unscroll* by 3 lines, which means that 3 lines will move from the'
|
||||
' scrollback buffer onto the top of the screen. :code:`1r-` will scroll to the previous prompt and 1r to the next prompt.'
|
||||
' See :ac:`scroll_to_prompt` for details on how scrolling to prompt works.'
|
||||
)
|
||||
options_spec = MATCH_WINDOW_OPTION + '''\n
|
||||
--no-response
|
||||
@@ -45,11 +49,12 @@ using this option means that you will not be notified of failures.
|
||||
if amt not in ('start', 'end'):
|
||||
pages = 'p' in amt
|
||||
unscroll = 'u' in amt
|
||||
prompt = 'r' in amt
|
||||
mult = -1 if amt.endswith('-') and not unscroll else 1
|
||||
q = float(amt.rstrip('+-plu'))
|
||||
q = float(amt.rstrip('+-plur'))
|
||||
if not pages and not q.is_integer():
|
||||
self.fatal('The number must be an integer')
|
||||
amount = q * mult, 'p' if pages else ('u' if unscroll else 'l')
|
||||
amount = q * mult, 'p' if pages else ('u' if unscroll else ('r' if prompt else 'l'))
|
||||
|
||||
# defaults to scroll the window this command is run in
|
||||
return {'match': opts.match, 'amount': amount, 'self': True}
|
||||
@@ -64,6 +69,8 @@ using this option means that you will not be notified of failures.
|
||||
amt, unit = amt
|
||||
if unit == 'u':
|
||||
window.screen.reverse_scroll(int(abs(amt)), True)
|
||||
elif unit == 'r':
|
||||
window.scroll_to_prompt(int(amt))
|
||||
else:
|
||||
unit = 'page' if unit == 'p' else 'line'
|
||||
if unit == 'page' and not isinstance(amt, int) and not amt.is_integer():
|
||||
|
||||
Reference in New Issue
Block a user