summaryrefslogtreecommitdiffstats
path: root/src/perl/readline
diff options
context:
space:
mode:
authorroot <root>2012-09-04 22:41:11 +0000
committerroot <root>2012-09-04 22:41:11 +0000
commitd50a22a63f36f3d4fb5bd2f4d7d0f89f36d84e8f (patch)
tree64566414b54ff274345437c2b02a4f1e73b80e72 /src/perl/readline
parent5ee396e7ac453f939e8ec74546756dba45906827 (diff)
*** empty log message ***
Diffstat (limited to 'src/perl/readline')
-rw-r--r--src/perl/readline92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/perl/readline b/src/perl/readline
new file mode 100644
index 0000000..b22677f
--- /dev/null
+++ b/src/perl/readline
@@ -0,0 +1,92 @@
+#! perl
+
+=head1 NAME
+
+readline - improve readline editing (enabled by default)
+
+=head1 DESCRIPTION
+
+A support package that tries to make editing with readline easier. At
+the moment, it reacts to clicking shift-left mouse button by trying to
+move the text cursor to this position. It does so by generating as many
+cursor-left or cursor-right keypresses as required (this only works
+for programs that correctly support wide characters).
+
+To avoid too many false positives, this is only done when:
+
+=over 4
+
+=item - the tty is in ICANON state.
+
+=item - the text cursor is visible.
+
+=item - the primary screen is currently being displayed.
+
+=item - the mouse is on the same (multi-row-) line as the text cursor.
+
+=back
+
+The normal selection mechanism isn't disabled, so quick successive clicks
+might interfere with selection creation in harmless ways.
+
+=cut
+
+use POSIX ();
+
+my $termios = new POSIX::Termios;
+
+sub on_init {
+ my ($self) = @_;
+
+ $self->{enabled} = 1;
+
+ push @{ $self->{term}{option_popup_hook} }, sub {
+ ("readline" => $self->{enabled}, sub { $self->{enabled} = shift })
+ };
+
+ ()
+}
+
+sub on_button_press {
+ my ($self, $event) = @_;
+
+ $self->current_screen || $self->hidden_cursor || !$self->{enabled}
+ and return;
+
+ my $mask = $self->ModLevel3Mask | $self->ModMetaMask
+ | urxvt::ShiftMask | urxvt::ControlMask;
+
+ ($event->{state} & $mask) == urxvt::ShiftMask
+ or return;
+
+ $termios->getattr ($self->pty_fd)
+ or return;
+
+ $termios->getlflag & &POSIX::ICANON
+ and return;
+
+ my ($row, $col) = $self->screen_cur;
+ my $line = $self->line ($row);
+ my $cur = $line->offset_of ($row, $col);
+ my $ofs = $line->offset_of ($event->{row}, $event->{col});
+
+ $ofs >= 0 && $ofs < $line->l
+ or return;
+
+ my $diff = $ofs - $cur;
+ my $move;
+
+ if ($diff < 0) {
+ ($ofs, $cur) = ($cur, $ofs);
+ $move = "\x1b[D";
+ } else {
+ $move = "\x1b[C";
+ }
+
+ my $skipped = substr $line->t, $cur, $ofs - $cur;
+ $skipped =~ s/\x{ffff}//g;
+
+ $self->tt_write ($move x length $skipped);
+
+ 1
+}