1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | =head1 NAME |
|
|
4 | |
|
|
5 | readline - improve readline editing (enabled by default) |
|
|
6 | |
|
|
7 | =head1 DESCRIPTION |
|
|
8 | |
|
|
9 | A support package that tries to make editing with readline easier. At |
|
|
10 | the moment, it reacts to clicking shift-left mouse button by trying to |
|
|
11 | move the text cursor to this position. It does so by generating as many |
|
|
12 | cursor-left or cursor-right keypresses as required (this only works |
|
|
13 | for programs that correctly support wide characters). |
|
|
14 | |
|
|
15 | To avoid too many false positives, this is only done when: |
|
|
16 | |
|
|
17 | =over 4 |
|
|
18 | |
|
|
19 | =item - the tty is in ICANON state. |
|
|
20 | |
|
|
21 | =item - the text cursor is visible. |
|
|
22 | |
|
|
23 | =item - the primary screen is currently being displayed. |
|
|
24 | |
|
|
25 | =item - the mouse is on the same (multi-row-) line as the text cursor. |
|
|
26 | |
|
|
27 | =back |
|
|
28 | |
|
|
29 | The normal selection mechanism isn't disabled, so quick successive clicks |
|
|
30 | might interfere with selection creation in harmless ways. |
|
|
31 | |
|
|
32 | =cut |
2 | |
33 | |
3 | use POSIX (); |
34 | use POSIX (); |
4 | |
35 | |
5 | my $termios = new POSIX::Termios; |
36 | my $termios = new POSIX::Termios; |
6 | |
37 | |
… | |
… | |
22 | $self->current_screen || $self->hidden_cursor || !$self->{enabled} |
53 | $self->current_screen || $self->hidden_cursor || !$self->{enabled} |
23 | and return; |
54 | and return; |
24 | |
55 | |
25 | my $mask = $self->ModLevel3Mask | $self->ModMetaMask |
56 | my $mask = $self->ModLevel3Mask | $self->ModMetaMask |
26 | | urxvt::ShiftMask | urxvt::ControlMask; |
57 | | urxvt::ShiftMask | urxvt::ControlMask; |
27 | |
58 | |
28 | ($event->{state} & $mask) == urxvt::ShiftMask |
59 | ($event->{state} & $mask) == urxvt::ShiftMask |
29 | or return; |
60 | or return; |
30 | |
61 | |
31 | $termios->getattr ($self->pty_fd) |
62 | $termios->getattr ($self->pty_fd) |
32 | or return; |
63 | or return; |
… | |
… | |
37 | my ($row, $col) = $self->screen_cur; |
68 | my ($row, $col) = $self->screen_cur; |
38 | my $line = $self->line ($row); |
69 | my $line = $self->line ($row); |
39 | my $cur = $line->offset_of ($row, $col); |
70 | my $cur = $line->offset_of ($row, $col); |
40 | my $ofs = $line->offset_of ($event->{row}, $event->{col}); |
71 | my $ofs = $line->offset_of ($event->{row}, $event->{col}); |
41 | |
72 | |
42 | if ($ofs >= 0 && $ofs < $line->l) { |
73 | $ofs >= 0 && $ofs < $line->l |
43 | my $diff = $ofs - $cur; |
74 | or return; |
44 | my $move; |
|
|
45 | |
75 | |
46 | if ($diff < 0) { |
76 | my $diff = $ofs - $cur; |
47 | ($ofs, $cur) = ($cur, $ofs); |
77 | my $move; |
48 | $move = "\x1b[D"; |
|
|
49 | } else { |
|
|
50 | $move = "\x1b[C"; |
|
|
51 | } |
|
|
52 | |
78 | |
53 | my $skipped = substr $line->t, $cur, $ofs - $cur; |
79 | if ($diff < 0) { |
54 | $skipped =~ s/\x{ffff}//g; |
80 | ($ofs, $cur) = ($cur, $ofs); |
55 | |
81 | $move = "\x1b[D"; |
56 | $self->tt_write ($move x length $skipped); |
82 | } else { |
57 | |
83 | $move = "\x1b[C"; |
58 | return 1; |
|
|
59 | } |
84 | } |
60 | |
85 | |
61 | () |
86 | my $skipped = substr $line->t, $cur, $ofs - $cur; |
|
|
87 | $skipped =~ s/\x{ffff}//g; |
|
|
88 | |
|
|
89 | $self->tt_write ($move x length $skipped); |
|
|
90 | |
|
|
91 | 1 |
62 | } |
92 | } |