3 # Convert a terminal color scheme for 256 color terminals to a GUI color
4 # scheme by adding the appropriate gui* options.
6 # Copyright (C) 2012-2014 Simon Ruderich
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 # Taken from the urxvt-8.2-256color.patch in Debian's urxvt-unicode
274 return if $color < 16 or $color > 255; # undef
276 my $value = $colors[$color - 16];
277 $value =~ s{^rgb:}{};
285 # Only handle lines with highlight commands.
286 if (/^\s*\bhi(?:ghlight)?\b/) {
287 foreach my $setting (m/\bcterm(?:fg|bg)?=\S+/g) {
288 my ($name, $value) = split /=/, $setting;
290 my $gui_name = $name;
291 $gui_name =~ s/cterm/gui/;
294 if ($name eq 'cterm') {
296 } elsif ($value eq 'NONE') {
299 $new_value = xterm2rgb($value);
302 # Update existing value.
303 if (/\b\Q$gui_name\E=/) {
304 s/\Q$gui_name\E=\S+/$gui_name=$new_value/;
305 # Append at the end of the line.
307 s/\n/ $gui_name=$new_value\n/;