1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
root |
1.6 |
use POSIX (); |
4 |
|
|
|
5 |
|
|
my $termios = new POSIX::Termios; |
6 |
|
|
|
7 |
root |
1.7 |
sub on_init { |
8 |
|
|
my ($self) = @_; |
9 |
|
|
|
10 |
|
|
$self->{enabled} = 1; |
11 |
|
|
|
12 |
|
|
push @{ $self->{term}{option_popup_hook} }, sub { |
13 |
|
|
("readline" => $self->{enabled}, sub { $self->{enabled} = shift }) |
14 |
|
|
}; |
15 |
|
|
|
16 |
|
|
() |
17 |
|
|
} |
18 |
|
|
|
19 |
root |
1.1 |
sub on_button_press { |
20 |
|
|
my ($self, $event) = @_; |
21 |
|
|
|
22 |
root |
1.4 |
return |
23 |
root |
1.7 |
if $self->current_screen || $self->hidden_cursor || !$self->{enabled}; |
24 |
root |
1.4 |
|
25 |
root |
1.6 |
$termios->getattr ($self->pty_fd) |
26 |
|
|
or return; |
27 |
|
|
|
28 |
|
|
return |
29 |
|
|
if $termios->getlflag & &POSIX::ICANON; |
30 |
|
|
|
31 |
root |
1.1 |
my ($row, $col) = $self->screen_cur; |
32 |
|
|
my $line = $self->line ($row); |
33 |
|
|
my $cur = $line->offset_of ($row, $col); |
34 |
|
|
my $ofs = $line->offset_of ($event->{row}, $event->{col}); |
35 |
|
|
|
36 |
root |
1.4 |
if ($ofs >= 0 && $ofs < $line->l) { |
37 |
root |
1.1 |
my $diff = $ofs - $cur; |
38 |
root |
1.3 |
my $move; |
39 |
root |
1.1 |
|
40 |
root |
1.3 |
if ($diff < 0) { |
41 |
|
|
($ofs, $cur) = ($cur, $ofs); |
42 |
|
|
$move = "\x1b[D"; |
43 |
|
|
} else { |
44 |
|
|
$move = "\x1b[C"; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
my $skipped = substr $line->t, $cur, $ofs - $cur; |
48 |
root |
1.5 |
$skipped =~ s/\x{ffff}//g; |
49 |
root |
1.3 |
|
50 |
|
|
$self->tt_write ($move x length $skipped); |
51 |
root |
1.1 |
} |
52 |
|
|
|
53 |
|
|
() |
54 |
|
|
} |