[pacman-dev] [PATCH 1/3] Updated pacsearch colors to match pacman's coloring

Pierre Neidhardt ambrevar at gmail.com
Wed Jan 15 11:43:58 EST 2014


On 14-01-15 18:50:07, Allan McRae wrote:
> >  #TODO: colors flag on commandline
> > +#TODO: for now the whole line is bold and some parts have the same formatting (e.g. extra and version), maybe it would be better to use regular formatting
> 
> No point changing this TODO and then removing it immediately in the next
> patch.  Just remove it.

Actually I was first going to submit only 1 patch with the TODO in it, but Dan
pushed me to finish the job. Hence this mess.

The same applies for all you comments about separate patches: I messed up
because I changed my mind about what I was going to submit. Will provide a new
serie of patches soon. Sorry for the inconvenience.

> > -# color a "repo/pkgname pkgver" line based on the repository name
> > +# define formatting variables
> > +my $FMT_BLUE = "\e[1;94m";
> > +my $FMT_CYAN = "\e[1;96m";
> > +my $FMT_GREEN = "\e[1;92m";
> > +my $FMT_MAGENTA = "\e[1;95m";
> > +my $FMT_RED = "\e[1;91m";
> > +my $FMT_YELLOW = "\e[1;93m";
> > +my $FMT_BOLD = "\e[1m";
> > +my $FMT_RESET = "\e[0m";

> You name these FMT_BLUE etc and then rename them to BLUE in the next
> patch.  Just use BLUE to be consistent with makepkg.

Did not know that makepkg was using the same variable names. Good thing though!

> > +# We try to stick to pacman colors.
> >  sub to_color {
> >  	my $line = shift;
> > -	# get the installed text colored first
> > -	$line =~ s/(\[.*\]$)/$INST$1$BASE/;
> > -	# and now the repo and dealings
> > -	$line =~ s/(^core\/.*)/$CLR1$1$BASE/;
> > -	$line =~ s/(^extra\/.*)/$CLR2$1$BASE/;
> > -	$line =~ s/(^community\/.*)/$CLR3$1$BASE/;
> > -	$line =~ s/(^testing\/.*)/$CLR4$1$BASE/;
> > -	$line =~ s/(^community-testing\/.*)/$CLR5$1$BASE/;
> > -	$line =~ s/(^multilib\/.*)/$CLR6$1$BASE/;
> > -	$line =~ s/(^local\/.*)/$CLR7$1$BASE/;
> > +	# get the installed text colored first (between square brackets)
> > +	$line =~ s/(\[.*\]$)/$FMT_CYAN$1$FMT_RESET/;
> > +	# group (between parentheses)
> > +	$line =~ s/(\(.*\))/$FMT_BLUE$1$FMT_RESET/;
> 
> Do we need FTM_RESET every time?   Surely CYAN just overwrites BLUE.
> More below...

Depends how we use formatting variables, since we can also turn bold characters
on/off.
For instance

  var = "$RED text in red"
  var = "$var $BOLD$BLUE text in bold blue"
  var = "$var $GREEN text in bold green"

In the third assignment, we might expect the last part to be non-bold since the
3rd line looks like the first one. This gets tricky when we start to concatenate
variables. As a safety measure, it can be good to reset formatting after each
assignment.

See below for another possiblity.

> > +	# version (second field)
> > +	$line =~ s/^([^ ]+) ([^ ]+) /$1 $FMT_GREEN$2$FMT_RESET /;
> > +	# name (word after slash)
> > +	$line =~ s/\/([\w-]*)/\/$FMT_BOLD$1$FMT_RESET/;
> 
> In pacman's output, the whole line is bold.  Why are you not doing that
> here?

I want repo formatting to be different from the other formatting. But with only
6 colors, we do not have much choice here.
So I've decided to leave the version/group/installed string non-bold so that
they appear different.

Then it's not on par with pacman. 3 possibilities:

* We leave the complete line bold, then we do not need to "reset" formatting as
told previously, we just change colors.

* We leave pacsearch and pacman output different.

* We change pacman output to match pacsearch.

What do you think?

-- 
Pierre Neidhardt

E.T. GO HOME!!!  (And take your Smurfs with you.)


More information about the pacman-dev mailing list