[pacman-dev] [PATCH] pacsearch colors and variable names
For now I've kept the original pacsearch colors for the repos. Some fields have the same colors--e.g. 'extra' and 'version' are both bold green. Maybe it would look nicer to make repo/name bold and to leave the other fields regular. I've changed repo-specific variables to formatting variables. Additionally I have rephrased the help message; the previous message would let one think this script was rather useless compared to a simple pacman -Ss. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 55 +++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 624f201..a05ae87 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -20,6 +20,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. #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 use strict; use warnings; @@ -29,7 +30,7 @@ my $myver = '@PACKAGE_VERSION@'; sub usage { print "$myname (pacman) v$myver\n\n"; - print "Add color and install information to a 'pacman -Ss' search\n\n"; + print "Perform a pacman search using both the local and the sync databases.\n\n"; print "Usage: $myname <pattern>\n\n"; print "Example: $myname ^gnome\n"; } @@ -54,32 +55,38 @@ if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") { exit 0; } -# define our colors to use when printing -my $CLR1 = "\e[0;34m"; -my $CLR2 = "\e[0;32m"; -my $CLR3 = "\e[0;35m"; -my $CLR4 = "\e[0;36m"; -my $CLR5 = "\e[0;31m"; -my $CLR6 = "\e[0;33m"; -my $CLR7 = "\e[1;36m"; -my $INST = "\e[1;31m"; -my $BASE = "\e[0m"; - -# 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"; + +# Color a "repo/pkgname pkgver (goups) [installed]" line. +# 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/; + # version (second field) + $line =~ s/^([^ ]+) ([^ ]+) /$1 $FMT_GREEN$2$FMT_RESET /; + # name (word after slash) + $line =~ s/\/([\w-]*)/\/$FMT_BOLD$1$FMT_RESET/; + # repo (word before slash inclusive) + $line =~ s/(^core\/)/$FMT_BLUE$1$FMT_RESET/; + $line =~ s/(^extra\/)/$FMT_GREEN$1$FMT_RESET/; + $line =~ s/(^community\/)/$FMT_MAGENTA$1$FMT_RESET/; + $line =~ s/(^testing\/)/$FMT_CYAN$1$FMT_RESET/; + $line =~ s/(^community-testing\/)/$FMT_RED$1$FMT_RESET/; + $line =~ s/(^multilib\/)/$FMT_YELLOW$1$FMT_RESET/; + $line =~ s/(^local\/)/$FMT_CYAN$1$FMT_RESET/; # any other unknown repository - $line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/; + $line =~ s/(^[\w-]*\/)/$FMT_YELLOW$1$FMT_RESET/; return $line; } -- 1.8.5.2
On Wed, Jan 8, 2014 at 12:23 PM, Pierre Neidhardt <ambrevar@gmail.com> wrote:
For now I've kept the original pacsearch colors for the repos. Some fields have the same colors--e.g. 'extra' and 'version' are both bold green. Maybe it would look nicer to make repo/name bold and to leave the other fields regular. I've changed repo-specific variables to formatting variables.
Additionally I have rephrased the help message; the previous message would let one think this script was rather useless compared to a simple pacman -Ss.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 55 +++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-)
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 624f201..a05ae87 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -20,6 +20,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>.
#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
use strict; use warnings; @@ -29,7 +30,7 @@ my $myver = '@PACKAGE_VERSION@';
sub usage { print "$myname (pacman) v$myver\n\n"; - print "Add color and install information to a 'pacman -Ss' search\n\n"; + print "Perform a pacman search using both the local and the sync databases.\n\n"; print "Usage: $myname <pattern>\n\n"; print "Example: $myname ^gnome\n"; } @@ -54,32 +55,38 @@ if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") { exit 0; }
-# define our colors to use when printing -my $CLR1 = "\e[0;34m"; -my $CLR2 = "\e[0;32m"; -my $CLR3 = "\e[0;35m"; -my $CLR4 = "\e[0;36m"; -my $CLR5 = "\e[0;31m"; -my $CLR6 = "\e[0;33m"; -my $CLR7 = "\e[1;36m"; -my $INST = "\e[1;31m"; -my $BASE = "\e[0m"; - -# 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"; + +# Color a "repo/pkgname pkgver (goups) [installed]" line. +# 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/; + # version (second field) + $line =~ s/^([^ ]+) ([^ ]+) /$1 $FMT_GREEN$2$FMT_RESET /; + # name (word after slash) + $line =~ s/\/([\w-]*)/\/$FMT_BOLD$1$FMT_RESET/;
You have mixed tabs and spaces in the above block.
+ # repo (word before slash inclusive) + $line =~ s/(^core\/)/$FMT_BLUE$1$FMT_RESET/; + $line =~ s/(^extra\/)/$FMT_GREEN$1$FMT_RESET/; + $line =~ s/(^community\/)/$FMT_MAGENTA$1$FMT_RESET/; + $line =~ s/(^testing\/)/$FMT_CYAN$1$FMT_RESET/; + $line =~ s/(^community-testing\/)/$FMT_RED$1$FMT_RESET/; + $line =~ s/(^multilib\/)/$FMT_YELLOW$1$FMT_RESET/; + $line =~ s/(^local\/)/$FMT_CYAN$1$FMT_RESET/;
I decided to compare the output of 'pacman -Ss vim' with 'pacsearch vim', and I found the output of pacsearch to be quite jarring---notably the use of a single color for the entire "repo/package version (group)" line. This isn't because of your patch because I'm using the version that's in the Arch repos now, but it's something we might want to look into after your patch gets applied. Jason
# any other unknown repository - $line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/; + $line =~ s/(^[\w-]*\/)/$FMT_YELLOW$1$FMT_RESET/; return $line; }
-- 1.8.5.2
On 14-01-08 18:14:05, Jason St. John wrote:
On Wed, Jan 8, 2014 at 12:23 PM, Pierre Neidhardt <ambrevar@gmail.com> wrote:
[...] +# Color a "repo/pkgname pkgver (goups) [installed]" line. +# 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/; + # version (second field) + $line =~ s/^([^ ]+) ([^ ]+) /$1 $FMT_GREEN$2$FMT_RESET /; + # name (word after slash) + $line =~ s/\/([\w-]*)/\/$FMT_BOLD$1$FMT_RESET/;
You have mixed tabs and spaces in the above block.
Sorry for that. Need another patch?
+ # repo (word before slash inclusive) + $line =~ s/(^core\/)/$FMT_BLUE$1$FMT_RESET/; + $line =~ s/(^extra\/)/$FMT_GREEN$1$FMT_RESET/; + $line =~ s/(^community\/)/$FMT_MAGENTA$1$FMT_RESET/; + $line =~ s/(^testing\/)/$FMT_CYAN$1$FMT_RESET/; + $line =~ s/(^community-testing\/)/$FMT_RED$1$FMT_RESET/; + $line =~ s/(^multilib\/)/$FMT_YELLOW$1$FMT_RESET/; + $line =~ s/(^local\/)/$FMT_CYAN$1$FMT_RESET/;
I decided to compare the output of 'pacman -Ss vim' with 'pacsearch vim', and I found the output of pacsearch to be quite jarring---notably the use of a single color for the entire "repo/package version (group)" line. This isn't because of your patch because I'm using the version that's in the Arch repos now, but it's something we might want to look into after your patch gets applied.
Jason
I'm not sure I got you right on this, because this is exactly the purpose of my patch: to get pacman and pacsearch coloring scheme on par. The only difference being the repo's color, a pacsearch specific feature which I decided to keep. As it has been discussed before, it should be less Arch specific and color any active repos in a consistent manner, whatever their name may be. -- Pierre Neidhardt The only difference in the game of love over the last few thousand years is that they've changed trumps from clubs to diamonds. -- The Indianapolis Star
On Wed, Jan 8, 2014 at 6:54 PM, Pierre Neidhardt <ambrevar@gmail.com> wrote:
On 14-01-08 18:14:05, Jason St. John wrote:
On Wed, Jan 8, 2014 at 12:23 PM, Pierre Neidhardt <ambrevar@gmail.com> wrote:
[...] +# Color a "repo/pkgname pkgver (goups) [installed]" line. +# 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/; + # version (second field) + $line =~ s/^([^ ]+) ([^ ]+) /$1 $FMT_GREEN$2$FMT_RESET /; + # name (word after slash) + $line =~ s/\/([\w-]*)/\/$FMT_BOLD$1$FMT_RESET/;
You have mixed tabs and spaces in the above block.
Sorry for that. Need another patch?
That decision is for Allan.
+ # repo (word before slash inclusive) + $line =~ s/(^core\/)/$FMT_BLUE$1$FMT_RESET/; + $line =~ s/(^extra\/)/$FMT_GREEN$1$FMT_RESET/; + $line =~ s/(^community\/)/$FMT_MAGENTA$1$FMT_RESET/; + $line =~ s/(^testing\/)/$FMT_CYAN$1$FMT_RESET/; + $line =~ s/(^community-testing\/)/$FMT_RED$1$FMT_RESET/; + $line =~ s/(^multilib\/)/$FMT_YELLOW$1$FMT_RESET/; + $line =~ s/(^local\/)/$FMT_CYAN$1$FMT_RESET/;
I decided to compare the output of 'pacman -Ss vim' with 'pacsearch vim', and I found the output of pacsearch to be quite jarring---notably the use of a single color for the entire "repo/package version (group)" line. This isn't because of your patch because I'm using the version that's in the Arch repos now, but it's something we might want to look into after your patch gets applied.
Jason
I'm not sure I got you right on this, because this is exactly the purpose of my patch: to get pacman and pacsearch coloring scheme on par. The only difference being the repo's color, a pacsearch specific feature which I decided to keep. As it has been discussed before, it should be less Arch specific and color any active repos in a consistent manner, whatever their name may be.
-- Pierre Neidhardt
Sorry. That was my mistake; I should have read more context before replying. I just locally applied your patch, and pacsearch output looks much, much better. One other thing I noticed---and I don't know if this is actually an issue or not---the color for "[installed]" has been changed from red to cyan. Jason
On 14-01-08 19:55:38, Jason St. John wrote:
One other thing I noticed---and I don't know if this is actually an issue or not---the color for "[installed]" has been changed from red to cyan.
Well, pacman outputs "[installed]" in cyan, so I think I'm getting things here, aren't I? Anyway, this reminds me of another issue: the string "installed" is hard coded, so it does not take the locale into account! Try to run pacsearch on a local package (e.g. a package installed from the AUR) and you will see. I've managed to fix this issue with a gettext. By the way I've implemented a Arch-agnostic version, added a -n, --nocolor option, and fixed a performance issue. Will submit a new patch as soon as possible. -- Pierre Neidhardt The best thing about growing older is that it takes such a long time.
participants (2)
-
Jason St. John
-
Pierre Neidhardt