From a451c43fd41137ce8050f984979fa33864441c34 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 10 Oct 2008 00:11:40 +0000 Subject: [PATCH] *** empty log message *** --- src/command.C | 4 ++-- src/perl/overlay-osc | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/rxvt.h | 2 +- src/urxvt.pm | 31 +++++++++++++++++------- 4 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 src/perl/overlay-osc diff --git a/src/command.C b/src/command.C index bea25165..f508ee8f 100644 --- a/src/command.C +++ b/src/command.C @@ -3274,6 +3274,7 @@ rxvt_term::process_xterm_seq (int op, const char *str, char resp) if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END))) return; + fprintf (stderr, "op %d<%s>\n", op, str);//D switch (op) { @@ -3511,8 +3512,7 @@ rxvt_term::process_xterm_seq (int op, const char *str, char resp) #if ENABLE_PERL case URxvt_perl: - if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END))) - ; // no responses yet + HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END)); break; #endif } diff --git a/src/perl/overlay-osc b/src/perl/overlay-osc new file mode 100644 index 00000000..88918f1e --- /dev/null +++ b/src/perl/overlay-osc @@ -0,0 +1,57 @@ +#! perl + +# allows programs to open popups +# printf "\033]777;overlay;action;args\007" +# +# action "simple;;;;;" +# printf "\033]777;overlay;simple;ov1;0;0;t;test\007" +# +## action "complex;;;;;;;;;" + +# action "timeout;;" +# printf "\033]777;overlay;timeout;ov1;6\007" + +# action "destroy;" + +sub on_osc_seq_perl { + my ($self, $osc, $resp) = @_; + + return unless $osc =~ s/^overlay;//; + + $osc =~ s/^([^;]+)+;// + or return; + + if ($1 eq "timeout") { + my ($id, $to) = split /;/, $osc, 2; + my $ov = $self->{ov}{$id} + or return; + if (length $to) { + $ov->{to}->start (urxvt::NOW + $to); + } else { + delete $ov->{to}; + } + + } elsif ($1 eq "simple") { + my ($id, $x, $y, $t, $txt) = split /;/, $osc, 5; + if ($t eq "h") { + $txt = pack "H*", $txt; + utf8::decode $txt; + } + $self->{ov}{$id} = { + ov => $self->overlay_simple ($x, $y, $txt), + to => urxvt::timer + ->new + ->start (urxvt::NOW + 60) + ->cb(sub { + delete $self->{ov}{$id}; + }), + }; + + } elsif ($1 eq "destroy") { + delete $self->{ov}{$osc}; + } + + 1 +} + + diff --git a/src/rxvt.h b/src/rxvt.h index 7a652b30..3978d25c 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -421,7 +421,7 @@ enum { URxvt_view_up = 720, URxvt_view_down = 721, - URxvt_perl = 777, + URxvt_perl = 777, // for use by perl extensions, starts with "extension-name;" }; /* Words starting with `Color_' are colours. Others are counts */ diff --git a/src/urxvt.pm b/src/urxvt.pm index 93d9db5b..75d8e7fd 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -543,29 +543,42 @@ It is called before lines are scrolled out (so rows 0 .. min ($lines - 1, $nrow - 1) represent the lines to be scrolled out). C<$saved> is the total number of lines that will be in the scrollback buffer. -=item on_osc_seq $term, $op, $args +=item on_osc_seq $term, $op, $args, $resp Called on every OSC sequence and can be used to suppress it or modify its -behaviour. The default should be to return an empty list. A true value +behaviour. The default should be to return an empty list. A true value suppresses execution of the request completely. Make sure you don't get -confused by recursive invocations when you output an osc sequence within +confused by recursive invocations when you output an OSC sequence within this callback. C should be used for new behaviour. -=item on_osc_seq_perl $term, $string +=item on_osc_seq_perl $term, $args, $resp Called whenever the B command sequence (OSC = operating system command) is processed. Cursor position and other state information is up-to-date when this happens. For interoperability, the -string should start with the extension name and a colon, to distinguish -it from commands for other extensions, and this might be enforced in the -future. +string should start with the extension name (sans -osc) and a semicolon, +to distinguish it from commands for other extensions, and this might be +enforced in the future. + +For example, C uses this: + + sub on_osc_seq_perl { + my ($self, $osc, $resp) = @_; + + return unless $osc =~ s/^overlay;//; + + ... process remaining $osc string + } Be careful not ever to trust (in a security sense) the data you receive, as its source can not easily be controlled (e-mail content, messages from other users on the same system etc.). +For responses, C<$resp> contains the end-of-args separator used by the +sender. + =item on_add_lines $term, $string Called whenever text is about to be output, with the text as argument. You @@ -595,8 +608,8 @@ you cannot just toggle rendition bits, but only set them. =item on_refresh_begin $term -Called just before the screen gets redrawn. Can be used for overlay -or similar effects by modify terminal contents in refresh_begin, and +Called just before the screen gets redrawn. Can be used for overlay or +similar effects by modifying the terminal contents in refresh_begin, and restoring them in refresh_end. The built-in overlay and selection display code is run after this hook, and takes precedence. -- 2.34.1