File: cursor_selection.py

package info (click to toggle)
fish 4.2.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,976 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (89 lines) | stat: -rw-r--r-- 2,591 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/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()

# 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, "!"

sendline("bind ctrl-space begin-selection")
expect_prompt()
sendline("bind ! 'echo -n \"<$(commandline --current-selection)>\"'")
expect_prompt()

# Test inclusive mode

sendline("set fish_cursor_selection_mode inclusive")

# at the beginning of the line
sendline("echo" + home + select + dump)
expect_str("<e>")
sendline("echo" + home + select + right + dump)
expect_str("<ec>")
sendline("echo" + home + right + select + left + dump)
expect_str("<ec>")

# in the middle of the line
sendline("echo" + home + right + select + dump)
expect_str("<c>")
sendline("echo" + home + right + select + right + dump)
expect_str("<ch>")
sendline("echo" + home + right + right + select + left + dump)
expect_str("<ch>")

# at the end of the line
sendline("echo" + end + select + dump)
expect_str("<>")
sendline("echo" + end + select + left + dump)
expect_str("<o>")
sendline("echo" + end + left + select + right + dump)
expect_str("<o>")

# Test exclusive mode

sendline("set fish_cursor_selection_mode exclusive")

# at the beginning of the line
sendline("echo" + home + select + dump)
expect_str("<>")
sendline("echo" + home + select + right + dump)
expect_str("<e>")
sendline("echo" + home + right + select + left + dump)
expect_str("<e>")

# in the middle of the line
sendline("echo" + home + right + select + dump)
expect_str("<>")
sendline("echo" + home + right + select + right + dump)
expect_str("<c>")
sendline("echo" + home + right + right + select + left + dump)
expect_str("<c>")

# at the end of the line
sendline("echo" + end + select + dump)
expect_str("<>")
sendline("echo" + end + select + left + dump)
expect_str("<o>")
sendline("echo" + end + left + select + right + dump)
expect_str("<o>")

# 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>")