Remote control: allow scrolling to prev/next prompt

This commit is contained in:
Kovid Goyal
2025-02-18 19:17:10 +05:30
parent eb5a9bc6a3
commit f29bc638ce
3 changed files with 20 additions and 7 deletions

View File

@@ -120,6 +120,8 @@ Detailed list of changes
- Speed up rendering of box drawing characters by moving the implementation to native code
- Remote control: `kitten @ scroll-window`: Allow scrolling to previous/next prompt
- macOS: Fix fallback font rendering for bold/italic text not working for some symbols that are present in the Menlo regular face but not the bold/italic faces (:iss:`8282`)
- XTGETTCAP: Fix response invalid for empty string capabilities (:pull:`8304`)
@@ -131,6 +133,7 @@ Detailed list of changes
- Fix a regression in 0.39.0 that caused a crash on invalid Unicode with a
large number of combining characters in a single cell (:iss:`8318`)
0.39.1 [2025-02-01]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -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():

View File

@@ -16,11 +16,12 @@ func parse_scroll_amount(amt string) ([]any, error) {
} else {
pages := strings.Contains(amt, "p")
unscroll := strings.Contains(amt, "u")
prompt := strings.Contains(amt, "r")
var mult float64 = 1
if strings.HasSuffix(amt, "-") && !unscroll {
mult = -1
}
q, err := strconv.ParseFloat(strings.TrimRight(amt, "+-plu"), 64)
q, err := strconv.ParseFloat(strings.TrimRight(amt, "+-plur"), 64)
if err != nil {
return ans, err
}
@@ -32,6 +33,8 @@ func parse_scroll_amount(amt string) ([]any, error) {
ans[1] = "p"
} else if unscroll {
ans[1] = "u"
} else if prompt {
ans[1] = "r"
} else {
ans[1] = "l"
}