sub on_init {
my ($self) = @_;
+ # force a refresh every second
$self->{digital_clock_refresh} = urxvt::timer
->new
->start (urxvt::NOW)
()
}
+# before refreshing: replace upper right with the clock display
sub on_refresh_begin {
my ($self) = @_;
my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0];
my $xpos = $self->ncol - length $time;
- $self->{digital_clock_rend} = $self->ROW_r (0, [(0x00020000 + urxvt::DEFAULT_RSTYLE) x length $time], $xpos);
+ $xpos >= 0
+ or return;
+
+ $self->{digital_clock_rend} = $self->ROW_r (0, [(urxvt::DEFAULT_RSTYLE) x length $time], $xpos);
$self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos);
()
}
+# after refreshing: restore previous screen contents
sub on_refresh_end {
my ($self) = @_;
- $self->ROW_r (0, $self->{digital_clock_rend});
- $self->ROW_t (0, $self->{digital_clock_text});
+ exists $self->{digital_clock_text}
+ or return;
+
+ $self->ROW_r (0, delete $self->{digital_clock_rend});
+ $self->ROW_t (0, delete $self->{digital_clock_text});
()
}
int len = wcslen (wstr);
- if (start_col + len > THIS->ncol)
+ if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
{
free (wstr);
- croak ("new_text extends beyond right margin");
+ croak ("new_text extends beyond horizontal margins");
}
for (int col = start_col; col < start_col + len; col++)
AV *av = (AV *)SvRV (new_rend);
int len = av_len (av) + 1;
- if (start_col + len > THIS->ncol)
- croak ("new_rend array extends beyond right margin");
+ if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
+ croak ("new_rend array extends beyond horizontal margins");
for (int col = start_col; col < start_col + len; col++)
{