1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
# this creates a simple digital clock by overwriting the refresh hooks |
4 |
|
|
|
5 |
|
|
sub on_init { |
6 |
|
|
my ($self) = @_; |
7 |
|
|
|
8 |
root |
1.3 |
# force a refresh every second |
9 |
root |
1.1 |
$self->{digital_clock_refresh} = urxvt::timer |
10 |
|
|
->new |
11 |
|
|
->start (urxvt::NOW) |
12 |
|
|
->cb (sub { |
13 |
root |
1.2 |
$self->{digital_clock_refresh}->start ($self->{digital_clock_refresh}->at + 1); |
14 |
root |
1.1 |
$self->want_refresh; |
15 |
|
|
}); |
16 |
|
|
|
17 |
|
|
() |
18 |
|
|
} |
19 |
|
|
|
20 |
root |
1.3 |
# before refreshing: replace upper right with the clock display |
21 |
root |
1.1 |
sub on_refresh_begin { |
22 |
|
|
my ($self) = @_; |
23 |
|
|
|
24 |
|
|
my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0]; |
25 |
|
|
my $xpos = $self->ncol - length $time; |
26 |
|
|
|
27 |
root |
1.3 |
$self->{digital_clock_rend} = $self->ROW_r (0, [(urxvt::DEFAULT_RSTYLE) x length $time], $xpos); |
28 |
root |
1.1 |
$self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos); |
29 |
|
|
|
30 |
|
|
() |
31 |
|
|
} |
32 |
|
|
|
33 |
root |
1.3 |
# after refreshing: restore previous screen contents |
34 |
root |
1.1 |
sub 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 |
|
|
|