[pacman-dev] [Patch] Disable colors and progress bars if TERM=dumb

2016-03-24 Thread Ivy Foster
I recently noticed that if colors and progress bars are enabled, pacman
will faithfully attempt to print them even to dumb terminals that cannot
handle them. This patch fixes that.

Cheers,
iff

>From 08d67cd6bbfd1bc29ebfae8eff80ffbf9e24fdf5 Mon Sep 17 00:00:00 2001
From: Ivy Foster 
Date: Thu, 24 Mar 2016 22:57:10 -0500
Subject: [PATCH] Disable colors and progress bars if TERM=dumb

Signed-off-by: Ivy Foster 
---
 src/pacman/conf.c   | 2 +-
 src/pacman/pacman.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 25de7af..39ea1ab 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -67,7 +67,7 @@ void enable_colors(int colors)
 {
colstr_t *colstr = >colstr;
 
-   if(colors == PM_COLOR_ON) {
+   if(colors == PM_COLOR_ON && strcmp(getenv("TERM"), "dumb") != 0) {
colstr->colon   = BOLDBLUE "::" BOLD " ";
colstr->title   = BOLD;
colstr->repo= BOLDMAGENTA;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index be52d1b..1d6d20f 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1110,7 +1110,7 @@ int main(int argc, char *argv[])
 
install_soft_interrupt_handler();
 
-   if(!isatty(fileno(stdout))) {
+   if(!isatty(fileno(stdout)) || strcmp(getenv("TERM"), "dumb") == 0) {
/* disable progressbar if the output is redirected */
config->noprogressbar = 1;
} else {
-- 
2.7.4


Re: [pacman-dev] Please make the colourised output exactly like that of "pacman-color"

2016-03-24 Thread Xavion
>
>
>- -Dk, -Dkk: the package name (but not the dependency) should be in
>bold, rather than quoted
>- -Qc: the package name should be in bold, rather than quoted
>
> I realised after sending my last email that removing the quotes would harm
monochrome 'pacman' users.  I find it hard to remember that we have to
factor in the poor souls who can't (yet) afford a colour monitor.


[pacman-dev] [PATCH] Added better colourisation support for certain operations: * Package Information: -Si and -Qi * Install Group: -S (group)

2016-03-24 Thread xavion . 0
From: Xavion 

Signed-off-by: Xavion 
---
 src/pacman/callback.c |  3 ++-
 src/pacman/package.c  | 55 ++-
 src/pacman/pacman.c   |  3 ++-
 src/pacman/sync.c |  7 ---
 src/pacman/util.c | 29 +--
 src/pacman/util.h |  4 ++--
 6 files changed, 57 insertions(+), 44 deletions(-)

diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 1e1a4cd..f7c69e2 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -436,7 +436,8 @@ void cb_question(alpm_question_t *question)
"The following package 
cannot be upgraded due to unresolvable dependencies:\n",
"The following packages 
cannot be upgraded due to unresolvable dependencies:\n",
count));
-   list_display(" ", namelist, getcols());
+   const colstr_t *colstr = >colstr;
+   list_display(" ", namelist, 
colstr->nocolor, getcols());
printf("\n");
q->skip = noyes(_n(
"Do you want to skip 
the above package for this upgrade?",
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 3ab9abc..fab1a5c 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -148,14 +148,14 @@ static void make_aligned_titles(void)
  * @param deps a list with items of type alpm_depend_t
  */
 static void deplist_display(const char *title,
-   alpm_list_t *deps, unsigned short cols)
+   alpm_list_t *deps, const char *colour, unsigned short cols)
 {
alpm_list_t *i, *text = NULL;
for(i = deps; i; i = alpm_list_next(i)) {
alpm_depend_t *dep = i->data;
text = alpm_list_add(text, alpm_dep_compute_string(dep));
}
-   list_display(title, text, cols);
+   list_display(title, text, colour, cols);
FREELIST(text);
 }
 
@@ -256,29 +256,30 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
}
 
cols = getcols();
+   const colstr_t *colstr = >colstr;
 
/* actual output */
if(from == ALPM_PKG_FROM_SYNCDB) {
string_display(titles[T_REPOSITORY],
-   alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
+   alpm_db_get_name(alpm_pkg_get_db(pkg)), 
colstr->repo, cols);
}
-   string_display(titles[T_NAME], alpm_pkg_get_name(pkg), cols);
-   string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), cols);
-   string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), cols);
-   string_display(titles[T_ARCHITECTURE], alpm_pkg_get_arch(pkg), cols);
-   string_display(titles[T_URL], alpm_pkg_get_url(pkg), cols);
-   list_display(titles[T_LICENSES], alpm_pkg_get_licenses(pkg), cols);
-   list_display(titles[T_GROUPS], alpm_pkg_get_groups(pkg), cols);
-   deplist_display(titles[T_PROVIDES], alpm_pkg_get_provides(pkg), cols);
-   deplist_display(titles[T_DEPENDS_ON], alpm_pkg_get_depends(pkg), cols);
+   string_display(titles[T_NAME], alpm_pkg_get_name(pkg), colstr->title, 
cols);
+   string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), 
colstr->version, cols);
+   string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), 
colstr->nocolor, cols);
+   string_display(titles[T_ARCHITECTURE], alpm_pkg_get_arch(pkg), 
colstr->nocolor, cols);
+   string_display(titles[T_URL], alpm_pkg_get_url(pkg), colstr->nocolor, 
cols);
+   list_display(titles[T_LICENSES], alpm_pkg_get_licenses(pkg), 
colstr->nocolor, cols);
+   list_display(titles[T_GROUPS], alpm_pkg_get_groups(pkg), 
colstr->groups, cols);
+   deplist_display(titles[T_PROVIDES], alpm_pkg_get_provides(pkg), 
colstr->nocolor, cols);
+   deplist_display(titles[T_DEPENDS_ON], alpm_pkg_get_depends(pkg), 
colstr->nocolor, cols);
optdeplist_display(pkg, cols);
 
if(extra || from == ALPM_PKG_FROM_LOCALDB) {
-   list_display(titles[T_REQUIRED_BY], requiredby, cols);
-   list_display(titles[T_OPTIONAL_FOR], optionalfor, cols);
+   list_display(titles[T_REQUIRED_BY], requiredby, 
colstr->nocolor, cols);
+   list_display(titles[T_OPTIONAL_FOR], optionalfor, 
colstr->nocolor, cols);
}
-   deplist_display(titles[T_CONFLICTS_WITH], alpm_pkg_get_conflicts(pkg), 
cols);
-   deplist_display(titles[T_REPLACES], alpm_pkg_get_replaces(pkg), cols);
+   deplist_display(titles[T_CONFLICTS_WITH], alpm_pkg_get_conflicts(pkg), 
colstr->nocolor, cols);
+   deplist_display(titles[T_REPLACES], alpm_pkg_get_replaces(pkg), 
colstr->nocolor, cols);
 
size = humanize_size(alpm_pkg_get_size(pkg), '\0', 2, );
if(from == 

Re: [pacman-dev] Please make the colourised output exactly like that of "pacman-color"

2016-03-24 Thread Xavion
Hi Allan,

I have become old and grumpy since then!
>

Okay, point taken: I did let it drag on a bit.  It wasn't all my fault,
though: I got sick of waiting for those other three patches to be merged in.


> Lets start with what is already justified by what we already have in
> pacman with the aim of improving consistency of our current colour
> scheme.  Further additions will need to be discussed separately.
>
> package names - bold  (in some places...)
> groups - blue
> repos - magenta
> versions - green
>
> So, I'd like separate patches:
>
> -Si/-Qi: just those changes
> -S group dialog: just those changes
>

Righto, you're the boss.  I've just created a patch for those switches
alone; I will post it to this thread soon.  I'll get back to you about the
other colours at a later date.


> -Qo/-Fo can have the same done
> and anywhere else that is currently not consistent.
>

As far as I can tell, the following switches need better colourisation.
Let me know if you disagree with any of this *before* I go ahead and create
the patch :-).

   - -Dk, -Dkk: the package name (but not the dependency) should be in
   bold, rather than quoted
   - -Qc: the package name should be in bold, rather than quoted
   - -Qg, -Sg: the group name should be in blue; the package name should be
   in bold
   - -Qk, -Qkk: the package name should be in bold
   - -Qo, -Fo: the package name should be in bold; the version number
   should be in green
   - -Qq, -Fq, -Sq: the package name should (possibly) be in bold
   - -T: the package name should (possibly) be in bold


-- 
Regards, Xavion.