pacsearch: using pacman color theme
No more per-repo coloring: this was not Arch-agnostic, and there is no reasonable, simple way to color repos in a consistant manner with only 6 colors. 'local' is in red: this way we benefit from the pacman -Ss && pacman -Qs combo. to_color subroutine: it takes an array instead of a string, this is faster and simpler. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
fe19a0c58d
commit
1e07af1b0a
1 changed files with 14 additions and 18 deletions
|
@ -69,21 +69,20 @@ $RESET = color('reset');
|
||||||
# localization
|
# localization
|
||||||
my $LC_INSTALLED = `gettext pacman installed`;
|
my $LC_INSTALLED = `gettext pacman installed`;
|
||||||
|
|
||||||
# color a "repo/pkgname pkgver" line based on the repository name
|
# Color a "repo/pkgname pkgver (groups) [installed]" line.
|
||||||
|
# We try to stick to pacman colors.
|
||||||
sub to_color {
|
sub to_color {
|
||||||
my $line = shift;
|
my @v = @_;
|
||||||
# get the installed text colored first
|
my $line = "$RESET$BOLD";
|
||||||
$line =~ s/(\[.*\]$)/$CYAN$1$RESET/;
|
if ( "$v[0]" eq "local" ) {
|
||||||
# and now the repo and dealings
|
$line .= "$RED";
|
||||||
$line =~ s/(^core\/.*)/$MAGENTA$1$RESET/;
|
} else {
|
||||||
$line =~ s/(^extra\/.*)/$MAGENTA$1$RESET/;
|
$line .= "$MAGENTA";
|
||||||
$line =~ s/(^community\/.*)/$MAGENTA$1$RESET/;
|
}
|
||||||
$line =~ s/(^testing\/.*)/$MAGENTA$1$RESET/;
|
$line .= "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]";
|
||||||
$line =~ s/(^community-testing\/.*)/$MAGENTA$1$RESET/;
|
$line .= " $BLUE$v[3]" if $v[3] ne "";
|
||||||
$line =~ s/(^multilib\/.*)/$MAGENTA$1$RESET/;
|
$line .= " $CYAN$v[4]" if $v[4] ne "";
|
||||||
$line =~ s/(^local\/.*)/$RED$1$RESET/;
|
$line .= " $RESET";
|
||||||
# any other unknown repository
|
|
||||||
$line =~ s/(^[\w-]*\/.*)/$RED$1$RESET/;
|
|
||||||
return $line;
|
return $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,10 +144,7 @@ foreach $_ (@querypkgs) {
|
||||||
# sort by original order (the last field) and print
|
# sort by original order (the last field) and print
|
||||||
foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) {
|
foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) {
|
||||||
my @v = @{$allpkgs{$_}};
|
my @v = @{$allpkgs{$_}};
|
||||||
my $line = "$v[0]/$v[1] $v[2]";
|
my $line = to_color(@v);
|
||||||
$line .= " $v[3]" if $v[3] ne "";
|
|
||||||
$line .= " $v[4]" if $v[4] ne "";
|
|
||||||
$line = to_color($line);
|
|
||||||
# print colorized "repo/pkgname pkgver ..." string with possible installed text
|
# print colorized "repo/pkgname pkgver ..." string with possible installed text
|
||||||
print "$line\n";
|
print "$line\n";
|
||||||
print "$v[5]\n";
|
print "$v[5]\n";
|
||||||
|
|
Loading…
Add table
Reference in a new issue