2022-07-01 16:26:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
|
|
|
|
sp = SpawnedProc()
|
|
|
|
sendline, expect_prompt, expect_str = sp.sendline, sp.expect_prompt, sp.expect_str
|
|
|
|
expect_prompt()
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# Set up key bindings
|
|
|
|
|
|
|
|
# Movement keys from the default key bindings
|
|
|
|
home, end = "\x01", "\x05" # Ctrl-A, Ctrl-E
|
|
|
|
left, right ="\x02", "\x06" # Ctrl-B, Ctrl-F
|
|
|
|
|
|
|
|
# Additional keys to start selecting and dump the current selection
|
|
|
|
select, dump = "\x00", "!" # Ctrl-Space, "!"
|
|
|
|
|
2022-07-01 16:26:00 +00:00
|
|
|
sendline("bind -k nul begin-selection")
|
|
|
|
expect_prompt()
|
|
|
|
sendline("bind ! 'echo -n \"<$(commandline --current-selection)>\"'")
|
|
|
|
expect_prompt()
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# Test inclusive mode
|
|
|
|
|
2022-07-01 16:26:00 +00:00
|
|
|
sendline("set fish_cursor_selection_mode inclusive")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# at the beginning of the line
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + select + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<e>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + select + right + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<ec>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + select + left + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<ec>")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# in the middle of the line
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + select + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<c>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + select + right + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<ch>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + right + select + left + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<ch>")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# at the end of the line
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + end + select + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + end + select + left + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<o>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + end + left + select + right + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<o>")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# Test exclusive mode
|
|
|
|
|
2022-07-01 16:26:00 +00:00
|
|
|
sendline("set fish_cursor_selection_mode exclusive")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# at the beginning of the line
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + select + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + select + right + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<e>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + select + left + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<e>")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# in the middle of the line
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + select + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + select + right + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<c>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + home + right + right + select + left + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<c>")
|
|
|
|
|
2022-07-03 03:38:16 +00:00
|
|
|
# at the end of the line
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + end + select + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + end + select + left + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<o>")
|
2022-07-02 15:49:20 +00:00
|
|
|
sendline("echo" + end + left + select + right + dump)
|
2022-07-01 16:26:00 +00:00
|
|
|
expect_str("<o>")
|
2022-07-03 03:38:16 +00:00
|
|
|
|
|
|
|
# Test default setting.
|
|
|
|
# We only test that the correct implementation is chosen and rely on the detailed tests from above.
|
|
|
|
|
|
|
|
# without a configured selection mode
|
|
|
|
sendline("set -u fish_cursor_selection_mode")
|
|
|
|
sendline("echo" + home + right + select + right + dump)
|
|
|
|
expect_str("<c>")
|
|
|
|
|
|
|
|
# with an unknown setting
|
|
|
|
sendline("set fish_cursor_selection_mode unknown")
|
|
|
|
sendline("echo" + home + right + select + right + dump)
|
|
|
|
expect_str("<c>")
|