fish-shell/tests/checks/tmux-complete.fish
Johannes Altmanninger 83b0294fc9 ctrl-l to scroll content instead of erasing screen
On ctrl-l we send `\e[2J` (Erase in Display).  Some terminals interpret
this to scroll the screen content instead of clearing it. This happens
on VTE-based terminals like gnome-terminal for example.

The traditional behavior of ctrl-l erasing the screen (but not the
rest of the scrollback) is weird because:

1. `ctrl-l` is the easiest and most portable way to push the prompt
   to the top (and repaint after glitches I guess). But it's also a
   destructive action, truncating scrollback. I use it for scrolling
   and am frequently surprised when my scroll back is missing
   information.
2. the amount of lines erased depends on the window size.
   It would be more intuitive to erase by prompts, or erase the text
   in the terminal selection.

Let's use scrolling behavior on all terminals.

The new command could also be named "push-to-scrollback", for
consistency with others. But if we anticipate a want to add other
scrollback-related commands, "scrollback-push" is better.

This causes tests/checks/tmux-history-search.fish to fail; that test
seems pretty broken; M-d (alt-d) is supposed to delete the current
search match but there is a rogue "echo" that is supposed to invalidate
the search match.  I'm not sure how that ever worked.

Also, pexepect doesn't seem to support cursor position reporting,
so work around that.

Ref: https://codeberg.org/dnkl/foot/wiki#how-do-i-make-ctrl-l-scroll-the-content-instead-of-erasing-it
as of wiki commit b57489e298f95d037fdf34da00ea60a5e8eafd6d

Closes #10934
2024-12-30 10:50:38 +01:00

118 lines
4.1 KiB
Fish

#RUN: %fish %s
#REQUIRES: command -v tmux
#REQUIRES: uname -r | grep -qv Microsoft
# disable on github actions because it's flakey
#REQUIRES: test -z "$CI"
isolated-tmux-start
# Don't escape existing token (#7526).
echo >file-1
echo >file-2
isolated-tmux send-keys 'HOME=$PWD ls ~/' Tab
tmux-sleep
isolated-tmux capture-pane -p
# Note the contents may or may not have the autosuggestion appended - it is a race.
# CHECK: prompt 0> HOME=$PWD ls ~/file-{{1?}}
# CHECK: ~/file-1 ~/file-2
# No pager on single smartcase completion (#7738).
isolated-tmux send-keys C-u C-l 'mkdir cmake CMakeFiles' Enter C-l \
'cat cmake' Tab
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 1> cat cmake/
# Correct case in pager when prefixes differ in case (#7743).
isolated-tmux send-keys C-u C-l 'complete -c foo2 -a "aabc aaBd" -f' Enter C-l \
'foo2 A' Tab
tmux-sleep
isolated-tmux capture-pane -p
# The "bc" part is the autosuggestion - we could use "capture-pane -e" to check colors.
# CHECK: prompt 2> foo2 aabc
# CHECK: aabc aaBd
# Check that a larger-than-screen completion list does not stomp a multiline commandline (#8509).
isolated-tmux send-keys C-u 'complete -c foo3 -fa "(seq $LINES)\t(string repeat -n $COLUMNS d)"' Enter \
C-l begin Enter foo3 Enter "echo some trailing line" \
C-p C-e Space Tab Tab
tmux-sleep
isolated-tmux capture-pane -p | sed -n '1p;$p'
# Assert that we didn't change the command line.
# CHECK: prompt 3> begin
# Also ensure that the pager is actually fully disclosed.
# CHECK: rows 1 to {{\d+}} of {{\d+}}
# Canceling the pager removes the inserted completion, no matter what happens in the search field.
# The common prefix remains because it is inserted before the pager is shown.
isolated-tmux send-keys C-c
tmux-sleep
isolated-tmux send-keys C-l foo2 Space BTab b BSpace b Escape
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 3> foo2 aa
# Check that down-or-search works even when the pager is not selected.
isolated-tmux send-keys C-u foo2 Space Tab
tmux-sleep
isolated-tmux send-keys Down
tmux-sleep
isolated-tmux capture-pane -p
# Also check that we show an autosuggestion.
# CHECK: prompt 3> foo2 aabc aabc
# CHECK: aabc{{ *}}aaBd
# Check that a larger-than-screen completion does not break down-or-search.
isolated-tmux send-keys C-u 'complete -c foo4 -f -a "
a-long-arg-\"$(seq $LINES | string pad -c_ --width $COLUMNS)\"
b-short-arg"' Enter C-l foo4 Space Tab Tab Down
tmux-sleep
isolated-tmux capture-pane -p | head -1
# The second one is the autosuggestion. Maybe we should turn them off for this test.
# TODO there should be a prefix ("prompt 4> foo4") but we fail to draw that in this case.
# CHECK: {{.*}} b-short-arg a-long-arg{{.*}}
# Check that completion pager followed by token search search inserts two separate tokens.
isolated-tmux send-keys C-u echo Space old-arg Enter C-l foo2 Space Tab Tab M-.
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 5> foo2 aabc old-arg
isolated-tmux send-keys C-u 'echo suggest this' Enter C-l
tmux-sleep
isolated-tmux send-keys 'echo sug' C-w C-z
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 6> echo suggest this
isolated-tmux send-keys C-u 'bind ctrl-s forward-single-char' Enter C-l
isolated-tmux send-keys 'echo suggest thi'
tmux-sleep
isolated-tmux send-keys C-s
tmux-sleep
isolated-tmux send-keys C-s
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 7> echo suggest this
isolated-tmux send-keys C-u
isolated-tmux send-keys 'echo sugg' C-a
tmux-sleep
isolated-tmux send-keys C-e M-f Space nothing
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 7> echo suggest nothing
isolated-tmux send-keys C-u 'bind \cs forward-char-passive' Enter C-l
isolated-tmux send-keys C-u 'bind \cb backward-char-passive' Enter C-l
isolated-tmux send-keys C-u 'echo do not accept this' Enter C-l
tmux-sleep
isolated-tmux send-keys 'echo do not accept thi' C-b C-b DC C-b C-s 'h'
tmux-sleep
isolated-tmux send-keys C-s C-s C-s 'x'
isolated-tmux capture-pane -p
# CHECK: prompt 10> echo do not accept thix
isolated-tmux send-keys C-u C-l ': {*,' Tab Tab Space ,
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 10> : {*,cmake/ ,{{.*}}