From 8dec307b5c563e419806e0024e9ca11b8340c5c4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 28 Nov 2021 11:29:03 +0100 Subject: Handle translating between colors internally. URXVT internal color indices, which are accepted by SET_COLOR are offset from the SGR color indices by 2. --- reselect | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/reselect b/reselect index ad7687a..81161fe 100644 --- a/reselect +++ b/reselect @@ -257,10 +257,20 @@ sub status_msg { } sub get_rend { - my ($self, $name, $default) = @_; - urxvt::SET_COLOR $default, - $self->my_resource("$name.foregroundColor") || urxvt::GET_BASEFG $default, - $self->my_resource("$name.backgroundColor") || urxvt::GET_BASEBG $default; + my ($self, $name, $rend) = @_; + # urxvt internal color indices are offset by 2 from the standard values + my $color_offset = 2; + + my $fg = $self->my_resource("$name.foregroundColor"); + if ($fg) { + $rend = urxvt::SET_FGCOLOR($rend, $color_offset + $fg); + } + my $bg = $self->my_resource("$name.backgroundColor"); + if ($bg) { + $rend = urxvt::SET_BGCOLOR($rend, $color_offset + $bg); + } + + return $rend; } sub on_key_release { -- cgit v1.2.3