ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/readline
Revision: 1.12
Committed: Sun Jun 10 17:31:53 2012 UTC (11 years, 11 months ago) by root
Branch: MAIN
Changes since 1.11: +31 -0 lines
Log Message:
move perl docs to extensions

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3 root 1.12 =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
33    
34 root 1.6 use POSIX ();
35    
36     my $termios = new POSIX::Termios;
37    
38 root 1.7 sub on_init {
39     my ($self) = @_;
40    
41     $self->{enabled} = 1;
42    
43     push @{ $self->{term}{option_popup_hook} }, sub {
44     ("readline" => $self->{enabled}, sub { $self->{enabled} = shift })
45     };
46    
47     ()
48     }
49    
50 root 1.1 sub on_button_press {
51     my ($self, $event) = @_;
52    
53 root 1.8 $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 sf-exg 1.11
59 root 1.8 ($event->{state} & $mask) == urxvt::ShiftMask
60     or return;
61 root 1.4
62 root 1.6 $termios->getattr ($self->pty_fd)
63     or return;
64    
65 root 1.8 $termios->getlflag & &POSIX::ICANON
66     and return;
67 root 1.6
68 root 1.1 my ($row, $col) = $self->screen_cur;
69     my $line = $self->line ($row);
70     my $cur = $line->offset_of ($row, $col);
71     my $ofs = $line->offset_of ($event->{row}, $event->{col});
72    
73 root 1.10 $ofs >= 0 && $ofs < $line->l
74     or return;
75 root 1.1
76 root 1.10 my $diff = $ofs - $cur;
77     my $move;
78 root 1.3
79 root 1.10 if ($diff < 0) {
80     ($ofs, $cur) = ($cur, $ofs);
81     $move = "\x1b[D";
82     } else {
83     $move = "\x1b[C";
84     }
85 root 1.3
86 root 1.10 my $skipped = substr $line->t, $cur, $ofs - $cur;
87     $skipped =~ s/\x{ffff}//g;
88 root 1.9
89 root 1.10 $self->tt_write ($move x length $skipped);
90 root 1.1
91 root 1.10 1
92 root 1.1 }