Por acaso, encontrei o wiki de configuração para mintty
. Tem muito de ótimas sugestões, uma das quais é como definir várias opções usando seqüências de escape para xterm
. Portanto, isso funciona por não ler a configuração novamente, mas interpretando sequências de escape para substituir as seleções de cores existentes.
Podemos usar isso do URxvt ligando uma chave a uma longa cadeia de comandos, cada um dos quais altera uma das 16 cores padrão.
Por exemplo, aqui eu defino alt+ctrl+l
para alterar todas as cores para C0C0C0:
# This stupidly changes every color to grey.
URxvt.keysym.M-C-l: command:3]11;#C0C0C0URxvt.keysym.M-1: command:3].......
73]10;#C0C0C0URxvt.keysym.M-C-l: command:3]4;12;#72729F9FCFCF#! /usr/bin/env perl -w
# Author: John Tyree
# Website: http://github.com/johntyree/urxvt-perls/blob/master/rotate-colors
# License: CCBYNC
# Use keyboard shortcuts to load colors of the form *.colorN:XXXXXX from a file
# This gives us "on demand" theme switching.
# Usage: put the following lines in your .Xdefaults/.Xresources:
# URxvt.perl-ext-common: ...,rotate-colors
# URxvt.colorFiles: ~/.Xresources,~/light.txt,~/dark.txt
# URxvt.keysym.M-C-n: perl:rotate-colors:forward
# URxvt.keysym.M-C-p: perl:rotate-colors:backward
use strict;
sub on_start {
my ($self) = @_;
$self->{current_index} = -1;
my @arr = split(/,/, $self->x_resource('colorFiles') || '');
$self->{color_files} = \@arr;
()
}
sub read_colors {
my $fn = shift;
open my $fin, $fn or print STDERR "Unable to open $fn for reading";
my %colors;
while (my $line = <$fin>) {
if ($line =~ /(\w+)\s*:\s*(#[0-9a-fA-F]+)/) {
$colors{$1} = $2;
}
}
return %colors
}
sub escape_seq {
my ($k, $v) = @_;
my $cmd = "";
if ($k =~ /^color(\d+)$/) {
$cmd = "4;$1;$v";
} elsif ($k =~ /^colorBD$/) {
$cmd = "5;0;$v";
} elsif ($k =~ /^colorUL$/) {
$cmd = "5;1;$v";
} elsif ($k =~ /^colorBL$/) {
$cmd = "5;2;$v";
} elsif ($k =~ /^colorRV$/) {
$cmd = "5;3;$v";
} elsif ($k =~ /^foreground$/) {
$cmd = "10;$v";
} elsif ($k =~ /^background$/) {
$cmd = "11;$v";
} elsif ($k =~ /^cursorColor$/) {
$cmd = "12;$v";
} elsif ($k =~ /^pointerColor$/) {
$cmd = "13;$v";
}
return "3]".$cmd."# This stupidly changes every color to grey.
URxvt.keysym.M-C-l: command:3]11;#C0C0C0URxvt.keysym.M-1: command:3].......
73]10;#C0C0C0URxvt.keysym.M-C-l: command:3]4;12;#72729F9FCFCF#! /usr/bin/env perl -w
# Author: John Tyree
# Website: http://github.com/johntyree/urxvt-perls/blob/master/rotate-colors
# License: CCBYNC
# Use keyboard shortcuts to load colors of the form *.colorN:XXXXXX from a file
# This gives us "on demand" theme switching.
# Usage: put the following lines in your .Xdefaults/.Xresources:
# URxvt.perl-ext-common: ...,rotate-colors
# URxvt.colorFiles: ~/.Xresources,~/light.txt,~/dark.txt
# URxvt.keysym.M-C-n: perl:rotate-colors:forward
# URxvt.keysym.M-C-p: perl:rotate-colors:backward
use strict;
sub on_start {
my ($self) = @_;
$self->{current_index} = -1;
my @arr = split(/,/, $self->x_resource('colorFiles') || '');
$self->{color_files} = \@arr;
()
}
sub read_colors {
my $fn = shift;
open my $fin, $fn or print STDERR "Unable to open $fn for reading";
my %colors;
while (my $line = <$fin>) {
if ($line =~ /(\w+)\s*:\s*(#[0-9a-fA-F]+)/) {
$colors{$1} = $2;
}
}
return %colors
}
sub escape_seq {
my ($k, $v) = @_;
my $cmd = "";
if ($k =~ /^color(\d+)$/) {
$cmd = "4;$1;$v";
} elsif ($k =~ /^colorBD$/) {
$cmd = "5;0;$v";
} elsif ($k =~ /^colorUL$/) {
$cmd = "5;1;$v";
} elsif ($k =~ /^colorBL$/) {
$cmd = "5;2;$v";
} elsif ($k =~ /^colorRV$/) {
$cmd = "5;3;$v";
} elsif ($k =~ /^foreground$/) {
$cmd = "10;$v";
} elsif ($k =~ /^background$/) {
$cmd = "11;$v";
} elsif ($k =~ /^cursorColor$/) {
$cmd = "12;$v";
} elsif ($k =~ /^pointerColor$/) {
$cmd = "13;$v";
}
return "3]".$cmd."%pre%7"
}
sub build_cmd {
my $fn = shift;
my %colors = read_colors($fn);
my $s = join("", map {escape_seq($_, $colors{$_})} keys %colors);
return $s # was implicit anyway
}
sub on_user_command {
my ($self, $cmd) = @_;
my @fs = @{$self->{color_files}};
my $len = @fs;
if ($cmd eq "rotate-colors:forward") {
my $idx = $self->{current_index}++;
my $fn = $fs[$idx % scalar(@fs)];
$self->cmd_parse(build_cmd($fn));
} elsif ($cmd eq "rotate-colors:backward") {
my $idx = $self->{current_index}--;
my $fn = $fs[$idx % scalar(@fs)];
$self->cmd_parse(build_cmd($fn));
}
()
}
73]4;1;#CCCC00000000%pre%73]4;15;#EEEEEEEEECEC%pre%73]4;14;#3434E2E2E2E2%pre%73]4;5;#757550507B7B%pre%73]4;3;#C4C4A0A00000%pre%73]4;7;#D3D3D7D7CFCF%pre%73]4;4;#34346565A4A4%pre%73]4;10;#8A8AE2E23434%pre%73]4;13;#ADAD7F7FA8A8%pre%73]4;8;#555557575353%pre%73]11;#FFFFFFFFFFFF%pre%73]4;9;#EFEF29292929%pre%73]4;2;#4E4E9A9A0606%pre%73]4;0;#2E2E34343636%pre%73]4;11;#FCFCE9E94F4F%pre%73]10;#000000000000%pre%73]4;6;#060698209A9A%pre%7
URxvt.keysym.M-C-d: command:3]4;12;#9090FF%pre%73]4;1;#AA0000%pre%73]4;15;#FFFFFF%pre%73]4;14;#55FFFF%pre%73]4;5;#AA00AA%pre%73]4;3;#AA5500%pre%73]4;7;#AAAAAA%pre%73]4;10;#55FF55%pre%73]4;13;#FF55FF%pre%73]4;4;#0000AD%pre%73]4;8;#555555%pre%73]11;#000000%pre%73]4;9;#FF5555%pre%73]4;2;#00AA00%pre%73]%pre%73]4;0;#000000%pre%73]4;11;#FFFF55%pre%73]10;#00FF00%pre%73]5;0;#00FF00%pre%73]4;6;#00AAAA%pre%7
73]4;0;#C0C0C0%pre%73]4;1;#C0C0C0%pre%73]4;2;#C0C0C0%pre%73]4;3;#C0C0C0%pre%73]4;4;#C0C0C0%pre%73]4;5;#C0C0C0%pre%73]4;6;#C0C0C0%pre%73]4;7;#C0C0C0%pre%73]4;8;#C0C0C0%pre%73]4;9;#C0C0C0%pre%73]4;10;#C0C0C0%pre%73]4;11;#C0C0C0%pre%73]4;12;#C0C0C0%pre%73]4;13;#C0C0C0%pre%73]4;14;#C0C0C0%pre%73]4;15;#C0C0C0%pre%7
7"
}
sub build_cmd {
my $fn = shift;
my %colors = read_colors($fn);
my $s = join("", map {escape_seq($_, $colors{$_})} keys %colors);
return $s # was implicit anyway
}
sub on_user_command {
my ($self, $cmd) = @_;
my @fs = @{$self->{color_files}};
my $len = @fs;
if ($cmd eq "rotate-colors:forward") {
my $idx = $self->{current_index}++;
my $fn = $fs[$idx % scalar(@fs)];
$self->cmd_parse(build_cmd($fn));
} elsif ($cmd eq "rotate-colors:backward") {
my $idx = $self->{current_index}--;
my $fn = $fs[$idx % scalar(@fs)];
$self->cmd_parse(build_cmd($fn));
}
()
}
73]4;1;#CCCC00000000%pre%73]4;15;#EEEEEEEEECEC%pre%73]4;14;#3434E2E2E2E2%pre%73]4;5;#757550507B7B%pre%73]4;3;#C4C4A0A00000%pre%73]4;7;#D3D3D7D7CFCF%pre%73]4;4;#34346565A4A4%pre%73]4;10;#8A8AE2E23434%pre%73]4;13;#ADAD7F7FA8A8%pre%73]4;8;#555557575353%pre%73]11;#FFFFFFFFFFFF%pre%73]4;9;#EFEF29292929%pre%73]4;2;#4E4E9A9A0606%pre%73]4;0;#2E2E34343636%pre%73]4;11;#FCFCE9E94F4F%pre%73]10;#000000000000%pre%73]4;6;#060698209A9A%pre%7
URxvt.keysym.M-C-d: command:3]4;12;#9090FF%pre%73]4;1;#AA0000%pre%73]4;15;#FFFFFF%pre%73]4;14;#55FFFF%pre%73]4;5;#AA00AA%pre%73]4;3;#AA5500%pre%73]4;7;#AAAAAA%pre%73]4;10;#55FF55%pre%73]4;13;#FF55FF%pre%73]4;4;#0000AD%pre%73]4;8;#555555%pre%73]11;#000000%pre%73]4;9;#FF5555%pre%73]4;2;#00AA00%pre%73]%pre%73]4;0;#000000%pre%73]4;11;#FFFF55%pre%73]10;#00FF00%pre%73]5;0;#00FF00%pre%73]4;6;#00AAAA%pre%7
73]4;0;#C0C0C0%pre%73]4;1;#C0C0C0%pre%73]4;2;#C0C0C0%pre%73]4;3;#C0C0C0%pre%73]4;4;#C0C0C0%pre%73]4;5;#C0C0C0%pre%73]4;6;#C0C0C0%pre%73]4;7;#C0C0C0%pre%73]4;8;#C0C0C0%pre%73]4;9;#C0C0C0%pre%73]4;10;#C0C0C0%pre%73]4;11;#C0C0C0%pre%73]4;12;#C0C0C0%pre%73]4;13;#C0C0C0%pre%73]4;14;#C0C0C0%pre%73]4;15;#C0C0C0%pre%7
Plugin Perl
Eu tenho isso "trabalhando", mas não realmente, porque parece que há um fundamental diferença entre recursos definidos como
%pre% e qualquer tentativa de fazer o mesmo com $term->cmd_parse()
.
Existe alguma coisa que possa ser feita sobre isso? Até agora eu tenho codificado inteiro conjuntos de cores claras e escuras usando sequências de escape (muito longas):
%pre%Isso funciona exatamente como eu esperava e poderia ser alternado em tempo de execução, então estou marcando isso como respondido, mas por que isso não pode ser feito dinamicamente a partir do Perl? Aqui está o que eu tenho até agora, eu não sou um ótimo codificador Perl, então, por favor, desculpe o estilo indubitavelmente ruim.
Espero que alguém possa concordar sobre qual é o problema. Este será um bom plugin. O upstream está no github .
%pre%