ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/digital-clock
(Generate patch)

Comparing rxvt-unicode/src/perl/digital-clock (file contents):
Revision 1.3 by root, Tue Jan 3 01:19:12 2006 UTC vs.
Revision 1.12 by root, Tue Sep 4 22:41:11 2012 UTC

1#! perl 1#! perl
2 2
3# this creates a simple digital clock by overwriting the refresh hooks 3=head1 NAME
4 4
5sub on_init { 5digital-clock - display a digital clock overlay
6
7=head1 DESCRIPTION
8
9Displays a digital clock using the built-in overlay.
10
11=cut
12
13sub on_start {
6 my ($self) = @_; 14 my ($self) = @_;
7 15
8 # force a refresh every second 16 $self->{overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0);
9 $self->{digital_clock_refresh} = urxvt::timer 17 $self->{timer} = urxvt::timer
10 ->new 18 ->new
11 ->start (urxvt::NOW) 19 ->start (1 + int urxvt::NOW) # make sure we update "on" the second
20 ->interval (1)
12 ->cb (sub { 21 ->cb (sub {
13 $self->{digital_clock_refresh}->start ($self->{digital_clock_refresh}->at + 1); 22 $self->{overlay}->set (0, 0,
14 $self->want_refresh; 23 sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]);
15 }); 24 });
16 25
17 () 26 ()
18} 27}
19 28
20# before refreshing: replace upper right with the clock display
21sub on_refresh_begin {
22 my ($self) = @_;
23 29
24 my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0];
25 my $xpos = $self->ncol - length $time;
26
27 $self->{digital_clock_rend} = $self->ROW_r (0, [(urxvt::DEFAULT_RSTYLE) x length $time], $xpos);
28 $self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos);
29
30 ()
31}
32
33# after refreshing: restore previous screen contents
34sub on_refresh_end {
35 my ($self) = @_;
36
37 $self->ROW_r (0, $self->{digital_clock_rend});
38 $self->ROW_t (0, $self->{digital_clock_text});
39
40 ()
41}
42
43

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines