ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/readline
(Generate patch)

Comparing rxvt-unicode/src/perl/readline (file contents):
Revision 1.7 by root, Mon Feb 6 06:14:08 2006 UTC vs.
Revision 1.12 by root, Sun Jun 10 17:31:53 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines