ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/example-refresh-hooks
Revision: 1.5
Committed: Tue Sep 4 22:41:11 2012 UTC (11 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rxvt-unicode-rel-9_29, rxvt-unicode-rel-9_26, rxvt-unicode-rel-9_25, rxvt-unicode-rel-9_22, rxvt-unicode-rel-9_20, rxvt-unicode-rel-9_21, rxvt-unicode-rel-9_19, rxvt-unicode-rel-9_18, rxvt-unicode-rel-9_17, rxvt-unicode-rel-9_16, rxvt-unicode-rel-9_30, HEAD
Changes since 1.4: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 =head1 NAME
4
5 example-refresh-hooks - example of how to use refresh hooks
6
7 =head1 DESCRIPTION
8
9 Displays a very simple digital clock in the upper right corner of the
10 window. Illustrates overwriting the refresh callbacks to create your own
11 overlays or changes.
12
13 =cut
14
15 sub on_init {
16 my ($self) = @_;
17
18 # force a refresh every second
19 $self->{digital_clock_refresh} = urxvt::timer
20 ->new
21 ->start (1 + int urxvt::NOW)
22 ->interval (1)
23 ->cb (sub { $self->want_refresh });
24
25 ()
26 }
27
28 # before refreshing: replace upper right with the clock display
29 sub on_refresh_begin {
30 my ($self) = @_;
31
32 my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0];
33 my $xpos = $self->ncol - length $time;
34
35 $xpos >= 0
36 or return;
37
38 $self->{digital_clock_rend} = $self->ROW_r (0, [(urxvt::DEFAULT_RSTYLE) x length $time], $xpos);
39 $self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos);
40
41 ()
42 }
43
44 # after refreshing: restore previous screen contents
45 sub on_refresh_end {
46 my ($self) = @_;
47
48 exists $self->{digital_clock_text}
49 or return;
50
51 $self->ROW_r (0, delete $self->{digital_clock_rend});
52 $self->ROW_t (0, delete $self->{digital_clock_text});
53
54 ()
55 }
56
57