Don't like ads? PRO users don't see any ads ;-)
Guest

pacman-color-3.4.1-1.patch

By: a guest on Sep 5th, 2010  |  syntax: Diff  |  size: 44.92 KB  |  hits: 222  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff -Naur pacman-3.4.1/src/pacman//callback.c pacman-color-3.4.1/src/pacman//callback.c
  2. --- pacman-3.4.1/src/pacman//callback.c 2010-07-03 01:23:20.000000000 +0200
  3. +++ pacman-color-3.4.1/src/pacman//callback.c   2010-09-05 23:07:49.691841728 +0200
  4. @@ -218,16 +218,16 @@
  5.                         printf(_("generating %s with %s... "), (char *)data1, (char *)data2);
  6.                         break;
  7.                 case PM_TRANS_EVT_DELTA_PATCH_DONE:
  8. -                       printf(_("success!\n"));
  9. +                       color_printf(COLOR_GREEN_ALL, _("success!\n"));
  10.                         break;
  11.                 case PM_TRANS_EVT_DELTA_PATCH_FAILED:
  12. -                       printf(_("failed.\n"));
  13. +                       color_printf(COLOR_RED_ALL, _("failed.\n"));
  14.                         break;
  15.                 case PM_TRANS_EVT_SCRIPTLET_INFO:
  16.                         printf("%s", (char*)data1);
  17.                         break;
  18.                 case PM_TRANS_EVT_RETRIEVE_START:
  19. -                       printf(_(":: Retrieving packages from %s...\n"), (char*)data1);
  20. +                       color_printf(COLOR_DOUBLECOLON, _(":: Retrieving packages from %s...\n"), (char*)data1);
  21.                         break;
  22.                 /* all the simple done events, with fallthrough for each */
  23.                 case PM_TRANS_EVT_FILECONFLICTS_DONE:
  24. @@ -250,11 +250,11 @@
  25.  {
  26.         switch(event) {
  27.                 case PM_TRANS_CONV_INSTALL_IGNOREPKG:
  28. -                       *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
  29. +                       *response = yesno(COLOR_DOUBLECOLON, _(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
  30.                                                           alpm_pkg_get_name(data1));
  31.                         break;
  32.                 case PM_TRANS_CONV_REPLACE_PKG:
  33. -                       *response = yesno(_(":: Replace %s with %s/%s?"),
  34. +                       *response = yesno(COLOR_DOUBLECOLON, _(":: Replace %s with %s/%s?"),
  35.                                         alpm_pkg_get_name(data1),
  36.                                         (char *)data3,
  37.                                         alpm_pkg_get_name(data2));
  38. @@ -263,12 +263,12 @@
  39.                         /* data parameters: target package, local package, conflict (strings) */
  40.                         /* print conflict only if it contains new information */
  41.                         if(!strcmp(data1, data3) || !strcmp(data2, data3)) {
  42. -                               *response = noyes(_(":: %s and %s are in conflict. Remove %s?"),
  43. +                               *response = noyes(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict. Remove %s?"),
  44.                                                 (char *)data1,
  45.                                                 (char *)data2,
  46.                                                 (char *)data2);
  47.                         } else {
  48. -                               *response = noyes(_(":: %s and %s are in conflict (%s). Remove %s?"),
  49. +                               *response = noyes(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict (%s). Remove %s?"),
  50.                                                 (char *)data1,
  51.                                                 (char *)data2,
  52.                                                 (char *)data3,
  53. @@ -283,17 +283,17 @@
  54.                                         namelist = alpm_list_add(namelist,
  55.                                                         (char *)alpm_pkg_get_name(i->data));
  56.                                 }
  57. -                               printf(_(":: the following package(s) cannot be upgraded due to "
  58. +                               color_printf(COLOR_DOUBLECOLON, _(":: the following package(s) cannot be upgraded due to "
  59.                                                 "unresolvable dependencies:\n"));
  60. -                               list_display("     ", namelist);
  61. -                               *response = noyes(_("\nDo you want to skip the above "
  62. +                               list_display(NULL, "     ", namelist);
  63. +                               *response = noyes(NULL, _("\nDo you want to skip the above "
  64.                                                         "package(s) for this upgrade?"));
  65.                                 alpm_list_free(namelist);
  66.                         }
  67.                         break;
  68.                 case PM_TRANS_CONV_LOCAL_NEWER:
  69.                         if(!config->op_s_downloadonly) {
  70. -                               *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"),
  71. +                               *response = yesno(COLOR_DOUBLECOLON, _(":: %s-%s: local version is newer. Upgrade anyway?"),
  72.                                                 alpm_pkg_get_name(data1),
  73.                                                 alpm_pkg_get_version(data1));
  74.                         } else {
  75. @@ -301,7 +301,7 @@
  76.                         }
  77.                         break;
  78.                 case PM_TRANS_CONV_CORRUPTED_PKG:
  79. -                       *response = yesno(_(":: File %s is corrupted. Do you want to delete it?"),
  80. +                       *response = yesno(COLOR_DOUBLECOLON, _(":: File %s is corrupted. Do you want to delete it?"),
  81.                                         (char *)data1);
  82.                         break;
  83.         }
  84. @@ -421,8 +421,8 @@
  85.  
  86.         }
  87.  
  88. -       printf("(%*d/%*d) %ls%-*s", digits, remain, digits, howmany,
  89. -                       wcstr, padwid, "");
  90. +       color_printf(COLOR_BLUE_ALL, "(%*d/%*d)", digits, remain, digits, howmany);
  91. +       printf(" %ls%-*s", wcstr, padwid, "");
  92.  
  93.         free(wcstr);
  94.  
  95. diff -Naur pacman-3.4.1/src/pacman//package.c pacman-color-3.4.1/src/pacman//package.c
  96. --- pacman-3.4.1/src/pacman//package.c  2010-07-03 01:23:20.000000000 +0200
  97. +++ pacman-color-3.4.1/src/pacman//package.c    2010-09-05 23:07:49.691841728 +0200
  98. @@ -91,47 +91,47 @@
  99.         }
  100.  
  101.         /* actual output */
  102. -       string_display(_("Name           :"), alpm_pkg_get_name(pkg));
  103. -       string_display(_("Version        :"), alpm_pkg_get_version(pkg));
  104. -       string_display(_("URL            :"), alpm_pkg_get_url(pkg));
  105. -       list_display(_("Licenses       :"), alpm_pkg_get_licenses(pkg));
  106. -       list_display(_("Groups         :"), alpm_pkg_get_groups(pkg));
  107. -       list_display(_("Provides       :"), alpm_pkg_get_provides(pkg));
  108. -       list_display(_("Depends On     :"), depstrings);
  109. -       list_display_linebreak(_("Optional Deps  :"), alpm_pkg_get_optdepends(pkg));
  110. +       color_string_display(COLOR_WHITE_ALL, _("Name           :"), COLOR_WHITE_ALL, alpm_pkg_get_name(pkg));
  111. +       color_string_display(COLOR_WHITE_ALL, _("Version        :"), COLOR_GREEN_ALL, alpm_pkg_get_version(pkg));
  112. +       color_string_display(COLOR_WHITE_ALL, _("URL            :"), COLOR_CYAN_ALL, alpm_pkg_get_url(pkg));
  113. +       list_display(COLOR_WHITE_ALL, _("Licenses       :"), alpm_pkg_get_licenses(pkg));
  114. +       list_display(COLOR_WHITE_ALL, _("Groups         :"), alpm_pkg_get_groups(pkg));
  115. +       list_display(COLOR_WHITE_ALL, _("Provides       :"), alpm_pkg_get_provides(pkg));
  116. +       list_display(COLOR_WHITE_ALL, _("Depends On     :"), depstrings);
  117. +       list_display_linebreak(COLOR_WHITE_ALL, _("Optional Deps  :"), alpm_pkg_get_optdepends(pkg));
  118.         if(level > 0 || level < -1) {
  119. -               list_display(_("Required By    :"), requiredby);
  120. +               list_display(COLOR_WHITE_ALL, _("Required By    :"), requiredby);
  121.         }
  122. -       list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
  123. -       list_display(_("Replaces       :"), alpm_pkg_get_replaces(pkg));
  124. +       list_display(COLOR_WHITE_ALL, _("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
  125. +       list_display(COLOR_WHITE_ALL, _("Replaces       :"), alpm_pkg_get_replaces(pkg));
  126.         if(level < 0) {
  127. -               printf(_("Download Size  : %6.2f K\n"),
  128. +               color_printf(COLOR_WHITE_COLON, _("Download Size  : %6.2f K\n"),
  129.                         (float)alpm_pkg_get_size(pkg) / 1024.0);
  130.         }
  131.         if(level == 0) {
  132. -               printf(_("Compressed Size: %6.2f K\n"),
  133. +               color_printf(COLOR_WHITE_COLON, _("Compressed Size: %6.2f K\n"),
  134.                         (float)alpm_pkg_get_size(pkg) / 1024.0);
  135.         }
  136.  
  137. -       printf(_("Installed Size : %6.2f K\n"),
  138. +       color_printf(COLOR_WHITE_COLON, _("Installed Size : %6.2f K\n"),
  139.                         (float)alpm_pkg_get_isize(pkg) / 1024.0);
  140. -       string_display(_("Packager       :"), alpm_pkg_get_packager(pkg));
  141. -       string_display(_("Architecture   :"), alpm_pkg_get_arch(pkg));
  142. -       string_display(_("Build Date     :"), bdatestr);
  143. +       string_display(COLOR_WHITE_ALL, _("Packager       :"), alpm_pkg_get_packager(pkg));
  144. +       string_display(COLOR_WHITE_ALL, _("Architecture   :"), alpm_pkg_get_arch(pkg));
  145. +       string_display(COLOR_WHITE_ALL, _("Build Date     :"), bdatestr);
  146.         if(level > 0) {
  147. -               string_display(_("Install Date   :"), idatestr);
  148. -               string_display(_("Install Reason :"), reason);
  149. +               string_display(COLOR_WHITE_ALL, _("Install Date   :"), idatestr);
  150. +               string_display(COLOR_WHITE_ALL, _("Install Reason :"), reason);
  151.         }
  152.         if(level >= 0) {
  153. -               string_display(_("Install Script :"),
  154. +               string_display(COLOR_WHITE_ALL, _("Install Script :"),
  155.                                 alpm_pkg_has_scriptlet(pkg) ?  _("Yes") : _("No"));
  156.         }
  157.  
  158.         /* MD5 Sum for sync package */
  159.         if(level < 0) {
  160. -               string_display(_("MD5 Sum        :"), alpm_pkg_get_md5sum(pkg));
  161. +               string_display(COLOR_WHITE_ALL, _("MD5 Sum        :"), alpm_pkg_get_md5sum(pkg));
  162.         }
  163. -       string_display(_("Description    :"), alpm_pkg_get_desc(pkg));
  164. +       string_display(COLOR_WHITE_ALL, _("Description    :"), alpm_pkg_get_desc(pkg));
  165.  
  166.         /* Print additional package info if info flag passed more than once */
  167.         if(level > 1) {
  168. @@ -152,7 +152,7 @@
  169.         if(pkg == NULL) {
  170.                 return;
  171.         }
  172. -       string_display(_("Repository     :"), treename);
  173. +       color_string_display(COLOR_WHITE_ALL, _("Repository     :"), COLOR_MAGENTA_ALL, treename);
  174.         /* invert the level since we are a sync package */
  175.         dump_pkg_full(pkg, -level);
  176.  }
  177. @@ -163,7 +163,7 @@
  178.  {
  179.         alpm_list_t *i;
  180.         const char *root = alpm_option_get_root();
  181. -       printf(_("Backup Files:\n"));
  182. +       color_printf(COLOR_WHITE_ALL, _("Backup Files:\n"));
  183.         if(alpm_pkg_get_backup(pkg)) {
  184.                 /* package has backup files, so print them */
  185.                 for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
  186. @@ -190,13 +190,13 @@
  187.  
  188.                                 /* if checksums don't match, file has been modified */
  189.                                 if (strcmp(md5sum, ptr)) {
  190. -                                       printf(_("MODIFIED\t%s\n"), path);
  191. +                                       color_printf(COLOR_YELLOW_ALL, _("MODIFIED\t%s\n"), path);
  192.                                 } else {
  193. -                                       printf(_("Not Modified\t%s\n"), path);
  194. +                                       color_printf(COLOR_GREEN_ALL, _("Not Modified\t%s\n"), path);
  195.                                 }
  196.                                 free(md5sum);
  197.                         } else {
  198. -                               printf(_("MISSING\t\t%s\n"), path);
  199. +                               color_printf(COLOR_RED_ALL, _("MISSING\t\t%s\n"), path);
  200.                         }
  201.                         free(str);
  202.                 }
  203. @@ -220,7 +220,8 @@
  204.         for(i = pkgfiles; i; i = alpm_list_next(i)) {
  205.                 filestr = alpm_list_getdata(i);
  206.                 if(!quiet){
  207. -                       fprintf(stdout, "%s %s%s\n", pkgname, root, filestr);
  208. +                       color_fprintf(stdout, COLOR_WHITE_ALL, "%s", pkgname);
  209. +                       fprintf(stdout, " %s%s\n", root, filestr);
  210.                 } else {
  211.                         fprintf(stdout, "%s%s\n", root, filestr);
  212.                 }
  213. diff -Naur pacman-3.4.1/src/pacman//pacman.c pacman-color-3.4.1/src/pacman//pacman.c
  214. --- pacman-3.4.1/src/pacman//pacman.c   2010-07-03 01:23:20.000000000 +0200
  215. +++ pacman-color-3.4.1/src/pacman//pacman.c     2010-09-05 23:07:49.691841728 +0200
  216. @@ -174,11 +174,22 @@
  217.   */
  218.  static void version(void)
  219.  {
  220. -       printf("\n");
  221. -       printf(" .--.                  Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version());
  222. -       printf("/ _.-' .-.  .-.  .-.   Copyright (C) 2006-2010 Pacman Development Team\n");
  223. -       printf("\\  '-. '-'  '-'  '-'   Copyright (C) 2002-2006 Judd Vinet\n");
  224. -       printf(" '--'\n");
  225. +       color_printf(COLOR_YELLOW_ALL, " .--. ");
  226. +       printf("        ");
  227. +       color_printf(COLOR_RED_ALL, " .---. ");
  228. +       printf("  Pacman-color v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version());
  229. +       color_printf(COLOR_YELLOW_ALL, "/ _.-'");
  230. +       color_printf(COLOR_WHITE_ALL, " .-.  .-");
  231. +       color_printf(COLOR_RED_ALL, "|O O  |");
  232. +       printf("  Copyright (C) 2006-2010 Pacman Development Team\n");
  233. +       color_printf(COLOR_YELLOW_ALL, "\\  '-.");
  234. +       color_printf(COLOR_WHITE_ALL, " '-'  '-");
  235. +       color_printf(COLOR_RED_ALL, "|~~~  |");
  236. +       printf("  Copyright (C) 2002-2006 Judd Vinet\n");
  237. +       color_printf(COLOR_YELLOW_ALL, " '--' ");
  238. +       printf("        ");
  239. +       color_printf(COLOR_RED_ALL, "|.-.-.|");
  240. +       printf("  Colored by vogo <vogo(at)seznam(dot)cz>\n");
  241.         printf(_("                       This program may be freely redistributed under\n"
  242.                  "                       the terms of the GNU General Public License.\n"));
  243.         printf("\n");
  244. @@ -1125,6 +1136,7 @@
  245.  
  246.         /* init config data */
  247.         config = config_new();
  248. +       parsecolorconfig();
  249.  
  250.         /* disable progressbar if the output is redirected */
  251.         if(!isatty(1)) {
  252. @@ -1196,17 +1208,17 @@
  253.  
  254.         if(config->verbose > 0) {
  255.                 alpm_list_t *i;
  256. -               printf("Root      : %s\n", alpm_option_get_root());
  257. -               printf("Conf File : %s\n", config->configfile);
  258. -               printf("DB Path   : %s\n", alpm_option_get_dbpath());
  259. -               printf("Cache Dirs: ");
  260. +               string_display(COLOR_WHITE_ALL, "Root      :", alpm_option_get_root());
  261. +               string_display(COLOR_WHITE_ALL, "Conf File :", config->configfile);
  262. +               string_display(COLOR_WHITE_ALL, "DB Path   :", alpm_option_get_dbpath());
  263. +               color_printf(COLOR_WHITE_ALL, "Cache Dirs: ");
  264.                 for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
  265.                         printf("%s  ", (char*)alpm_list_getdata(i));
  266.                 }
  267.                 printf("\n");
  268. -               printf("Lock File : %s\n", alpm_option_get_lockfile());
  269. -               printf("Log File  : %s\n", alpm_option_get_logfile());
  270. -               list_display("Targets   :", pm_targets);
  271. +               string_display(COLOR_WHITE_ALL, "Lock File :", alpm_option_get_lockfile());
  272. +               string_display(COLOR_WHITE_ALL, "Log File  :", alpm_option_get_logfile());
  273. +               list_display(COLOR_WHITE_ALL, "Targets   :", pm_targets);
  274.         }
  275.  
  276.         /* Opening local database */
  277. diff -Naur pacman-3.4.1/src/pacman//query.c pacman-color-3.4.1/src/pacman//query.c
  278. --- pacman-3.4.1/src/pacman//query.c    2010-06-24 15:23:29.000000000 +0200
  279. +++ pacman-color-3.4.1/src/pacman//query.c      2010-09-05 23:07:49.691841728 +0200
  280. @@ -220,7 +220,9 @@
  281.                 pmpkg_t *pkg = alpm_list_getdata(i);
  282.  
  283.                 if (!config->quiet) {
  284. -                       printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
  285. +                       color_printf(COLOR_MAGENTA_ALL, "local/");
  286. +                       color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
  287. +                       color_printf(COLOR_GREEN_ALL, "%s", alpm_pkg_get_version(pkg));
  288.                 } else {
  289.                         printf("%s", alpm_pkg_get_name(pkg));
  290.                 }
  291. @@ -237,16 +239,11 @@
  292.                 if (!config->quiet) {
  293.                         if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
  294.                                 alpm_list_t *k;
  295. -                               printf(" (");
  296. +                               color_printf(COLOR_BLUE_ALL, " (");
  297.                                 for(k = grp; k; k = alpm_list_next(k)) {
  298.                                         const char *group = alpm_list_getdata(k);
  299. -                                       printf("%s", group);
  300. -                                       if(alpm_list_next(k)) {
  301. -                                               /* only print a spacer if there are more groups */
  302. -                                               printf(" ");
  303. -                                       }
  304. +                                       color_printf(COLOR_BLUE_ALL, "%s%s", group, (alpm_list_next(k) ? " " : ")"));
  305.                                 }
  306. -                               printf(")");
  307.                         }
  308.  
  309.                         /* we need a newline and initial indent first */
  310. @@ -278,7 +275,8 @@
  311.                         packages = alpm_grp_get_pkgs(grp);
  312.  
  313.                         for(p = packages; p; p = alpm_list_next(p)) {
  314. -                               printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p)));
  315. +                               color_printf(COLOR_BLUE_ALL, "%s ", grpname);
  316. +                               color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
  317.                         }
  318.                 }
  319.         } else {
  320. @@ -290,8 +288,8 @@
  321.                                 const alpm_list_t *p, *packages = alpm_grp_get_pkgs(grp);
  322.                                 for(p = packages; p; p = alpm_list_next(p)) {
  323.                                         if(!config->quiet) {
  324. -                                               printf("%s %s\n", grpname,
  325. -                                                               alpm_pkg_get_name(alpm_list_getdata(p)));
  326. +                                               color_printf(COLOR_BLUE_ALL, "%s ", grpname);
  327. +                                               color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
  328.                                         } else {
  329.                                                 printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
  330.                                         }
  331. @@ -437,7 +435,8 @@
  332.         if(!config->op_q_info && !config->op_q_list
  333.                         && !config->op_q_changelog && !config->op_q_check) {
  334.                 if (!config->quiet) {
  335. -                       printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
  336. +                       color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
  337. +                       color_printf(COLOR_GREEN_ALL, "%s\n", alpm_pkg_get_version(pkg));
  338.                 } else {
  339.                         printf("%s\n", alpm_pkg_get_name(pkg));
  340.                 }
  341. diff -Naur pacman-3.4.1/src/pacman//remove.c pacman-color-3.4.1/src/pacman//remove.c
  342. --- pacman-3.4.1/src/pacman//remove.c   2010-06-24 15:23:29.000000000 +0200
  343. +++ pacman-color-3.4.1/src/pacman//remove.c     2010-09-05 23:07:49.691841728 +0200
  344. @@ -79,7 +79,7 @@
  345.                         case PM_ERR_PKG_INVALID_ARCH:
  346.                                 for(i = data; i; i = alpm_list_next(i)) {
  347.                                         char *pkg = alpm_list_getdata(i);
  348. -                                       printf(_(":: package %s does not have a valid architecture\n"), pkg);
  349. +                                       color_printf(COLOR_DOUBLECOLON, _(":: package %s does not have a valid architecture\n"), pkg);
  350.                                 }
  351.                                 break;
  352.                         case PM_ERR_UNSATISFIED_DEPS:
  353. @@ -87,7 +87,7 @@
  354.                                         pmdepmissing_t *miss = alpm_list_getdata(i);
  355.                                         pmdepend_t *dep = alpm_miss_get_dep(miss);
  356.                                         char *depstring = alpm_dep_compute_string(dep);
  357. -                                       printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
  358. +                                       color_printf(COLOR_DOUBLECOLON, _(":: %s: requires %s\n"), alpm_miss_get_target(miss),
  359.                                                         depstring);
  360.                                         free(depstring);
  361.                                 }
  362. @@ -110,7 +110,7 @@
  363.                         holdpkg = 1;
  364.                 }
  365.         }
  366. -       if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
  367. +       if(holdpkg && (noyes(NULL, _("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
  368.                 retval = 1;
  369.                 goto cleanup;
  370.         }
  371. @@ -130,7 +130,7 @@
  372.         /* print targets and ask user confirmation */
  373.         display_targets(pkglist, 0);
  374.         printf("\n");
  375. -       if(yesno(_("Do you want to remove these packages?")) == 0) {
  376. +       if(yesno(NULL, _("Do you want to remove these packages?")) == 0) {
  377.                 retval = 1;
  378.                 goto cleanup;
  379.         }
  380. diff -Naur pacman-3.4.1/src/pacman//sync.c pacman-color-3.4.1/src/pacman//sync.c
  381. --- pacman-3.4.1/src/pacman//sync.c     2010-07-03 01:23:20.000000000 +0200
  382. +++ pacman-color-3.4.1/src/pacman//sync.c       2010-09-05 23:07:49.691841728 +0200
  383. @@ -86,7 +86,7 @@
  384.                 /* We have a directory that doesn't match any syncdb.
  385.                  * Ask the user if he wants to remove it. */
  386.                 if(!found) {
  387. -                       if(!yesno(_("Do you want to remove %s?"), path)) {
  388. +                       if(!yesno(NULL, _("Do you want to remove %s?"), path)) {
  389.                                 continue;
  390.                         }
  391.  
  392. @@ -108,8 +108,8 @@
  393.         int ret = 0;
  394.  
  395.         dbpath = alpm_option_get_dbpath();
  396. -       printf(_("Database directory: %s\n"), dbpath);
  397. -       if(!yesno(_("Do you want to remove unused repositories?"))) {
  398. +       color_printf(COLOR_WHITE_COLON, _("Database directory: %s\n"), dbpath);
  399. +       if(!yesno(NULL, _("Do you want to remove unused repositories?"))) {
  400.                 return(0);
  401.         }
  402.         /* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/,
  403. @@ -131,18 +131,18 @@
  404.         int ret = 0;
  405.  
  406.         for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
  407. -               printf(_("Cache directory: %s\n"), (char*)alpm_list_getdata(i));
  408. +               color_printf(COLOR_WHITE_COLON, _("Cache directory: %s\n"), (char*)alpm_list_getdata(i));
  409.         }
  410.  
  411.         if(level == 1) {
  412.                 switch(config->cleanmethod) {
  413.                         case PM_CLEAN_KEEPINST:
  414. -                               if(!yesno(_("Do you want to remove uninstalled packages from cache?"))) {
  415. +                               if(!yesno(NULL, _("Do you want to remove uninstalled packages from cache?"))) {
  416.                                         return(0);
  417.                                 }
  418.                                 break;
  419.                         case PM_CLEAN_KEEPCUR:
  420. -                               if(!yesno(_("Do you want to remove outdated packages from cache?"))) {
  421. +                               if(!yesno(NULL, _("Do you want to remove outdated packages from cache?"))) {
  422.                                         return(0);
  423.                                 }
  424.                                 break;
  425. @@ -152,7 +152,7 @@
  426.                 }
  427.                 printf(_("removing old packages from cache...\n"));
  428.         } else {
  429. -               if(!noyes(_("Do you want to remove ALL files from cache?"))) {
  430. +               if(!noyes(NULL, _("Do you want to remove ALL files from cache?"))) {
  431.                         return(0);
  432.                 }
  433.                 printf(_("removing all files from cache...\n"));
  434. @@ -194,7 +194,7 @@
  435.                          * files here that aren't valid packages. we also don't need a full
  436.                          * load of the package, just the metadata. */
  437.                         if(alpm_pkg_load(path, 0, &localpkg) != 0 || localpkg == NULL) {
  438. -                               if(yesno(_("File %s does not seem to be a valid package, remove it?"), path)) {
  439. +                               if(yesno(NULL, _("File %s does not seem to be a valid package, remove it?"), path)) {
  440.                                         if(localpkg) {
  441.                                                 alpm_pkg_free(localpkg);
  442.                                         }
  443. @@ -321,8 +321,9 @@
  444.                         pmpkg_t *pkg = alpm_list_getdata(j);
  445.  
  446.                         if (!config->quiet) {
  447. -                               printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
  448. -                                                        alpm_pkg_get_version(pkg));
  449. +                               color_printf(COLOR_MAGENTA_ALL, "%s/", alpm_db_get_name(db));
  450. +                               color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
  451. +                               color_printf(COLOR_GREEN_ALL, "%s", alpm_pkg_get_version(pkg));
  452.                         } else {
  453.                                 printf("%s", alpm_pkg_get_name(pkg));
  454.                         }
  455. @@ -338,16 +339,11 @@
  456.                         if (!config->quiet) {
  457.                                 if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
  458.                                         alpm_list_t *k;
  459. -                                       printf(" (");
  460. +                                       color_printf(COLOR_BLUE_ALL, " (");
  461.                                         for(k = grp; k; k = alpm_list_next(k)) {
  462.                                                 const char *group = alpm_list_getdata(k);
  463. -                                               printf("%s", group);
  464. -                                               if(alpm_list_next(k)) {
  465. -                                                       /* only print a spacer if there are more groups */
  466. -                                                       printf(" ");
  467. -                                               }
  468. +                                               color_printf(COLOR_BLUE_ALL, "%s%s", group, (alpm_list_next(k) ? " " : ")"));
  469.                                         }
  470. -                                       printf(")");
  471.                                 }
  472.  
  473.                                 print_installed(pkg);
  474. @@ -382,8 +378,8 @@
  475.                                         /* get names of packages in group */
  476.                                         for(k = alpm_grp_get_pkgs(grp); k; k = alpm_list_next(k)) {
  477.                                                 if(!config->quiet) {
  478. -                                                       printf("%s %s\n", grpname,
  479. -                                                                       alpm_pkg_get_name(alpm_list_getdata(k)));
  480. +                                                       color_printf(COLOR_BLUE_ALL, "%s ", grpname);
  481. +                                                       color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
  482.                                                 } else {
  483.                                                         printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
  484.                                                 }
  485. @@ -401,8 +397,8 @@
  486.  
  487.                                 if(level > 1) {
  488.                                         for(k = alpm_grp_get_pkgs(grp); k; k = alpm_list_next(k)) {
  489. -                                               printf("%s %s\n", grpname,
  490. -                                                               alpm_pkg_get_name(alpm_list_getdata(k)));
  491. +                                               color_printf(COLOR_BLUE_ALL, "%s ", grpname);
  492. +                                               color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
  493.                                         }
  494.                                 } else {
  495.                                         /* print grp names only, no package names */
  496. @@ -538,8 +534,9 @@
  497.                         pmpkg_t *pkg = alpm_list_getdata(j);
  498.  
  499.                         if (!config->quiet) {
  500. -                               printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
  501. -                                               alpm_pkg_get_version(pkg));
  502. +                               color_printf(COLOR_MAGENTA_ALL, "%s ", alpm_db_get_name(db));
  503. +                               color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
  504. +                               color_printf(COLOR_GREEN_ALL, "%s\n", alpm_pkg_get_version(pkg));
  505.                                 print_installed(pkg);
  506.                                 printf("\n");
  507.                         } else {
  508. @@ -628,7 +625,7 @@
  509.         }
  510.  
  511.         if(config->op_s_upgrade) {
  512. -               printf(_(":: Starting full system upgrade...\n"));
  513. +               color_printf(COLOR_DOUBLECOLON, _(":: Starting full system upgrade...\n"));
  514.                 alpm_logaction("starting full system upgrade\n");
  515.                 if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) {
  516.                         pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
  517. @@ -646,7 +643,7 @@
  518.                         case PM_ERR_PKG_INVALID_ARCH:
  519.                                 for(i = data; i; i = alpm_list_next(i)) {
  520.                                         char *pkg = alpm_list_getdata(i);
  521. -                                       printf(_(":: package %s does not have a valid architecture\n"), pkg);
  522. +                                       color_printf(COLOR_DOUBLECOLON, _(":: package %s does not have a valid architecture\n"), pkg);
  523.                                 }
  524.                                 break;
  525.                         case PM_ERR_UNSATISFIED_DEPS:
  526. @@ -654,7 +651,7 @@
  527.                                         pmdepmissing_t *miss = alpm_list_getdata(i);
  528.                                         pmdepend_t *dep = alpm_miss_get_dep(miss);
  529.                                         char *depstring = alpm_dep_compute_string(dep);
  530. -                                       printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
  531. +                                       color_printf(COLOR_DOUBLECOLON, _(":: %s: requires %s\n"), alpm_miss_get_target(miss),
  532.                                                         depstring);
  533.                                         free(depstring);
  534.                                 }
  535. @@ -667,9 +664,9 @@
  536.                                         const char *reason = alpm_conflict_get_reason(conflict);
  537.                                         /* only print reason if it contains new information */
  538.                                         if(!strcmp(package1, reason) || !strcmp(package2, reason)) {
  539. -                                               printf(_(":: %s and %s are in conflict\n"), package1, package2);
  540. +                                               color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict\n"), package1, package2);
  541.                                         } else {
  542. -                                               printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
  543. +                                               color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
  544.                                         }
  545.                                 }
  546.                                 break;
  547. @@ -699,9 +696,9 @@
  548.  
  549.         int confirm;
  550.         if(config->op_s_downloadonly) {
  551. -               confirm = yesno(_("Proceed with download?"));
  552. +               confirm = yesno(NULL, _("Proceed with download?"));
  553.         } else {
  554. -               confirm = yesno(_("Proceed with installation?"));
  555. +               confirm = yesno(NULL, _("Proceed with installation?"));
  556.         }
  557.         if(!confirm) {
  558.                 goto cleanup;
  559. @@ -723,7 +720,7 @@
  560.                                                                         alpm_fileconflict_get_ctarget(conflict));
  561.                                                         break;
  562.                                                 case PM_FILECONFLICT_FILESYSTEM:
  563. -                                                       printf(_("%s: %s exists in filesystem\n"),
  564. +                                                       color_printf(COLOR_WHITE_COLON, _("%s: %s exists in filesystem\n"),
  565.                                                                         alpm_fileconflict_get_target(conflict),
  566.                                                                         alpm_fileconflict_get_file(conflict));
  567.                                                         break;
  568. @@ -741,7 +738,7 @@
  569.                                 break;
  570.                 }
  571.                 /* TODO: stderr? */
  572. -               printf(_("Errors occurred, no packages were upgraded.\n"));
  573. +               color_printf(COLOR_RED_ALL, _("Errors occurred, no packages were upgraded.\n"));
  574.                 retval = 1;
  575.                 goto cleanup;
  576.         }
  577. @@ -790,7 +787,7 @@
  578.  
  579.         if(config->op_s_sync) {
  580.                 /* grab a fresh package list */
  581. -               printf(_(":: Synchronizing package databases...\n"));
  582. +               color_printf(COLOR_DOUBLECOLON, _(":: Synchronizing package databases...\n"));
  583.                 alpm_logaction("synchronizing package lists\n");
  584.                 if(!sync_synctree(config->op_s_sync, sync_dbs)) {
  585.                         return(1);
  586. @@ -839,9 +836,9 @@
  587.                         alpm_list_t *tmp = NULL;
  588.                         if(config->op_s_upgrade || (tmp = alpm_list_diff(targets, packages, (alpm_list_fn_cmp)strcmp))) {
  589.                                 alpm_list_free(tmp);
  590. -                               printf(_(":: The following packages should be upgraded first :\n"));
  591. -                               list_display("   ", packages);
  592. -                               if(yesno(_(":: Do you want to cancel the current operation\n"
  593. +                               color_printf(COLOR_DOUBLECOLON, _(":: The following packages should be upgraded first :\n"));
  594. +                               list_display(NULL, "   ", packages);
  595. +                               if(yesno(COLOR_DOUBLECOLON2, _(":: Do you want to cancel the current operation\n"
  596.                                                                 ":: and upgrade these packages now?"))) {
  597.                                         FREELIST(targs);
  598.                                         targs = packages;
  599. diff -Naur pacman-3.4.1/src/pacman//upgrade.c pacman-color-3.4.1/src/pacman//upgrade.c
  600. --- pacman-3.4.1/src/pacman//upgrade.c  2010-07-03 01:23:20.000000000 +0200
  601. +++ pacman-color-3.4.1/src/pacman//upgrade.c    2010-09-05 23:07:49.691841728 +0200
  602. @@ -88,7 +88,7 @@
  603.                         case PM_ERR_PKG_INVALID_ARCH:
  604.                                 for(i = data; i; i = alpm_list_next(i)) {
  605.                                         char *pkg = alpm_list_getdata(i);
  606. -                                       printf(_(":: package %s does not have a valid architecture\n"), pkg);
  607. +                                       color_printf(COLOR_DOUBLECOLON, _(":: package %s does not have a valid architecture\n"), pkg);
  608.                                 }
  609.                                 break;
  610.                         case PM_ERR_UNSATISFIED_DEPS:
  611. @@ -100,7 +100,7 @@
  612.                                         /* TODO indicate if the error was a virtual package or not:
  613.                                          *              :: %s: requires %s, provided by %s
  614.                                          */
  615. -                                       printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
  616. +                                       color_printf(COLOR_DOUBLECOLON, _(":: %s: requires %s\n"), alpm_miss_get_target(miss),
  617.                                                         depstring);
  618.                                         free(depstring);
  619.                                 }
  620. @@ -113,9 +113,9 @@
  621.                                         const char *reason = alpm_conflict_get_reason(conflict);
  622.                                         /* only print reason if it contains new information */
  623.                                         if(!strcmp(package1, reason) || !strcmp(package2, reason)) {
  624. -                                               printf(_(":: %s and %s are in conflict\n"), package1, package2);
  625. +                                               color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict\n"), package1, package2);
  626.                                         } else {
  627. -                                               printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
  628. +                                               color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
  629.                                         }
  630.                                 }
  631.                                 break;
  632. @@ -145,7 +145,7 @@
  633.         display_targets(alpm_trans_get_remove(), 0);
  634.         display_targets(alpm_trans_get_add(), 1);
  635.         printf("\n");
  636. -       int confirm = yesno(_("Proceed with installation?"));
  637. +       int confirm = yesno(NULL, _("Proceed with installation?"));
  638.         if(!confirm) {
  639.                 trans_release();
  640.                 return(retval);
  641. @@ -167,7 +167,7 @@
  642.                                                                         alpm_fileconflict_get_ctarget(conflict));
  643.                                                         break;
  644.                                                 case PM_FILECONFLICT_FILESYSTEM:
  645. -                                                       printf(_("%s: %s exists in filesystem\n"),
  646. +                                                       color_printf(COLOR_WHITE_COLON, _("%s: %s exists in filesystem\n"),
  647.                                                                         alpm_fileconflict_get_target(conflict),
  648.                                                                         alpm_fileconflict_get_file(conflict));
  649.                                                         break;
  650. diff -Naur pacman-3.4.1/src/pacman//util.c pacman-color-3.4.1/src/pacman//util.c
  651. --- pacman-3.4.1/src/pacman//util.c     2010-07-27 17:10:55.000000000 +0200
  652. +++ pacman-color-3.4.1/src/pacman//util.c       2010-09-05 23:08:26.762672026 +0200
  653. @@ -45,6 +45,20 @@
  654.  #include "conf.h"
  655.  #include "callback.h"
  656.  
  657. +#define COLOR_LEN 8
  658. +
  659. +typedef struct __colortab_t {
  660. +       char red[COLOR_LEN + 1];
  661. +       char green[COLOR_LEN + 1];
  662. +       char yellow[COLOR_LEN + 1];
  663. +       char blue[COLOR_LEN + 1];
  664. +       char magenta[COLOR_LEN + 1];
  665. +       char cyan[COLOR_LEN + 1];
  666. +       char white[COLOR_LEN + 1];
  667. +       char none[COLOR_LEN + 1];
  668. +} colortab_t;
  669. +
  670. +static colortab_t colortab;
  671.  
  672.  int trans_init(pmtransflag_t flags)
  673.  {
  674. @@ -426,12 +440,12 @@
  675.         return(len);
  676.  }
  677.  
  678. -void string_display(const char *title, const char *string)
  679. +void string_display(const colordata_t *colors_title, const char *title, const char *string)
  680.  {
  681.         int len = 0;
  682.  
  683.         if(title) {
  684. -               printf("%s ", title);
  685. +               color_printf(colors_title, "%s ", title);
  686.         }
  687.         if(string == NULL || string[0] == '\0') {
  688.                 printf(_("None"));
  689. @@ -443,14 +457,14 @@
  690.         printf("\n");
  691.  }
  692.  
  693. -void list_display(const char *title, const alpm_list_t *list)
  694. +void list_display(const colordata_t *colors_title, const char *title, const alpm_list_t *list)
  695.  {
  696.         const alpm_list_t *i;
  697.         int cols, len = 0;
  698.  
  699.         if(title) {
  700.                 len = string_length(title) + 1;
  701. -               printf("%s ", title);
  702. +               color_printf(colors_title, "%s ", title);
  703.         }
  704.  
  705.         if(!list) {
  706. @@ -479,14 +493,14 @@
  707.         }
  708.  }
  709.  
  710. -void list_display_linebreak(const char *title, const alpm_list_t *list)
  711. +void list_display_linebreak(const colordata_t *colors_title, const char *title, const alpm_list_t *list)
  712.  {
  713.         const alpm_list_t *i;
  714.         int len = 0;
  715.  
  716.         if(title) {
  717.                 len = string_length(title) + 1;
  718. -               printf("%s ", title);
  719. +               color_printf(colors_title, "%s ", title);
  720.         }
  721.  
  722.         if(!list) {
  723. @@ -546,21 +560,21 @@
  724.  
  725.         if(install) {
  726.                 asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
  727. -               list_display(str, targets);
  728. +               list_display(COLOR_YELLOW_ALL, str, targets);
  729.                 free(str);
  730.                 printf("\n");
  731.  
  732. -               printf(_("Total Download Size:    %.2f MB\n"), mbdlsize);
  733. +               color_printf(COLOR_WHITE_COLON, _("Total Download Size:    %.2f MB\n"), mbdlsize);
  734.                 if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
  735. -                       printf(_("Total Installed Size:   %.2f MB\n"), mbisize);
  736. +                       color_printf(COLOR_WHITE_COLON, _("Total Installed Size:   %.2f MB\n"), mbisize);
  737.                 }
  738.         } else {
  739.                 asprintf(&str, _("Remove (%d):"), alpm_list_count(targets));
  740. -               list_display(str, targets);
  741. +               list_display(COLOR_RED_ALL, str, targets);
  742.                 free(str);
  743.                 printf("\n");
  744.  
  745. -               printf(_("Total Removed Size:   %.2f MB\n"), mbisize);
  746. +               color_printf(COLOR_WHITE_COLON, _("Total Removed Size:   %.2f MB\n"), mbisize);
  747.         }
  748.  
  749.         FREELIST(targets);
  750. @@ -672,7 +686,7 @@
  751.         alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
  752.         if(optdeps) {
  753.                 printf(_("New optional dependencies for %s\n"), alpm_pkg_get_name(newpkg));
  754. -               list_display_linebreak("   ", optdeps);
  755. +               list_display_linebreak(NULL, "   ", optdeps);
  756.         }
  757.         alpm_list_free(optdeps);
  758.  }
  759. @@ -682,12 +696,12 @@
  760.         alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
  761.         if(optdeps) {
  762.                 printf(_("Optional dependencies for %s\n"), alpm_pkg_get_name(pkg));
  763. -               list_display_linebreak("   ", optdeps);
  764. +               list_display_linebreak(NULL, "   ", optdeps);
  765.         }
  766.  }
  767.  
  768.  /* presents a prompt and gets a Y/N answer */
  769. -static int question(short preset, char *fmt, va_list args)
  770. +static int question(const colordata_t *colors, short preset, char *fmt, va_list args)
  771.  {
  772.         char response[32];
  773.         int sresponse = sizeof(response)-1;
  774. @@ -700,7 +714,7 @@
  775.                 stream = stderr;
  776.         }
  777.  
  778. -       vfprintf(stream, fmt, args);
  779. +       color_vfprintf(stream, colors, fmt, args);
  780.  
  781.         if(preset) {
  782.                 fprintf(stream, " %s ", _("[Y/n]"));
  783. @@ -728,25 +742,25 @@
  784.         return(0);
  785.  }
  786.  
  787. -int yesno(char *fmt, ...)
  788. +int yesno(const colordata_t *colors, char *fmt, ...)
  789.  {
  790.         int ret;
  791.         va_list args;
  792.  
  793.         va_start(args, fmt);
  794. -       ret = question(1, fmt, args);
  795. +       ret = question(colors, 1, fmt, args);
  796.         va_end(args);
  797.  
  798.         return(ret);
  799.  }
  800.  
  801. -int noyes(char *fmt, ...)
  802. +int noyes(const colordata_t *colors, char *fmt, ...)
  803.  {
  804.         int ret;
  805.         va_list args;
  806.  
  807.         va_start(args, fmt);
  808. -       ret = question(0, fmt, args);
  809. +       ret = question(colors, 0, fmt, args);
  810.         va_end(args);
  811.  
  812.         return(ret);
  813. @@ -792,21 +806,40 @@
  814.         ret = vasprintf(&msg, format, args);
  815.  
  816.         /* print a prefix to the message */
  817. -       switch(level) {
  818. -               case PM_LOG_DEBUG:
  819. -                       asprintf(string, "debug: %s", msg);
  820. -                       break;
  821. -               case PM_LOG_ERROR:
  822. -                       asprintf(string, _("error: %s"), msg);
  823. -                       break;
  824. -               case PM_LOG_WARNING:
  825. -                       asprintf(string, _("warning: %s"), msg);
  826. -                       break;
  827. -               case PM_LOG_FUNCTION:
  828. -                       asprintf(string, _("function: %s"), msg);
  829. -                       break;
  830. -               default:
  831. -                       break;
  832. +       if(isatty(fileno(stdout))) {
  833. +               switch(level) {
  834. +                       case PM_LOG_DEBUG:
  835. +                               asprintf(string, "debug: %s", msg);
  836. +                               break;
  837. +                       case PM_LOG_ERROR:
  838. +                               asprintf(string, "%s%s%s%s", colortab.red, _("error: "), colortab.none, msg);
  839. +                               break;
  840. +                       case PM_LOG_WARNING:
  841. +                               asprintf(string, "%s%s%s%s", colortab.yellow, _("warning: "), colortab.none, msg);
  842. +                               break;
  843. +                       case PM_LOG_FUNCTION:
  844. +                               asprintf(string, _("function: %s"), msg);
  845. +                               break;
  846. +                       default:
  847. +                               break;
  848. +               }
  849. +       } else {
  850. +               switch(level) {
  851. +                       case PM_LOG_DEBUG:
  852. +                               asprintf(string, "debug: %s", msg);
  853. +                               break;
  854. +                       case PM_LOG_ERROR:
  855. +                               asprintf(string, _("error: %s"), msg);
  856. +                               break;
  857. +                       case PM_LOG_WARNING:
  858. +                               asprintf(string, _("warning: %s"), msg);
  859. +                               break;
  860. +                       case PM_LOG_FUNCTION:
  861. +                               asprintf(string, _("function: %s"), msg);
  862. +                               break;
  863. +                       default:
  864. +                               break;
  865. +               }
  866.         }
  867.         free(msg);
  868.  
  869. @@ -844,10 +877,10 @@
  870.                         fprintf(stream, "debug: ");
  871.                         break;
  872.                 case PM_LOG_ERROR:
  873. -                       fprintf(stream, _("error: "));
  874. +                       color_fprintf(stream, COLOR_RED_ALL, _("error: "));
  875.                         break;
  876.                 case PM_LOG_WARNING:
  877. -                       fprintf(stream, _("warning: "));
  878. +                       color_fprintf(stream, COLOR_YELLOW_ALL, _("warning: "));
  879.                         break;
  880.                 case PM_LOG_FUNCTION:
  881.                   /* TODO we should increase the indent level when this occurs so we can see
  882. @@ -885,4 +918,310 @@
  883.  }
  884.  #endif
  885.  
  886. +/* pacman-color */
  887. +
  888. +int _set_color_sequence(const char* name, char* dest)
  889. +{
  890. +       int ret = 0;
  891. +
  892. +       if(strcmp(name, "black") == 0) {
  893. +               strncpy(dest, "\033[0;30m", COLOR_LEN);
  894. +       } else if(strcmp(name, "red") == 0) {
  895. +               strncpy(dest, "\033[0;31m", COLOR_LEN);
  896. +       } else if(strcmp(name, "green") == 0) {
  897. +               strncpy(dest, "\033[0;32m", COLOR_LEN);
  898. +       } else if(strcmp(name, "yellow") == 0) {
  899. +               strncpy(dest, "\033[0;33m", COLOR_LEN);
  900. +       } else if(strcmp(name, "blue") == 0) {
  901. +               strncpy(dest, "\033[0;34m", COLOR_LEN);
  902. +       } else if(strcmp(name, "magenta") == 0) {
  903. +               strncpy(dest, "\033[0;35m", COLOR_LEN);
  904. +       } else if(strcmp(name, "cyan") == 0) {
  905. +               strncpy(dest, "\033[0;36m", COLOR_LEN);
  906. +       } else if(strcmp(name, "white") == 0) {
  907. +               strncpy(dest, "\033[0;37m", COLOR_LEN);
  908. +       } else if(strcmp(name, "gray") == 0) {
  909. +               strncpy(dest, "\033[1;30m", COLOR_LEN);
  910. +       } else if(strcmp(name, "intensive red") == 0) {
  911. +               strncpy(dest, "\033[1;31m", COLOR_LEN);
  912. +       } else if(strcmp(name, "intensive green") == 0) {
  913. +               strncpy(dest, "\033[1;32m", COLOR_LEN);
  914. +       } else if(strcmp(name, "intensive yellow") == 0) {
  915. +               strncpy(dest, "\033[1;33m", COLOR_LEN);
  916. +       } else if(strcmp(name, "intensive blue") == 0) {
  917. +               strncpy(dest, "\033[1;34m", COLOR_LEN);
  918. +       } else if(strcmp(name, "intensive magenta") == 0) {
  919. +               strncpy(dest, "\033[1;35m", COLOR_LEN);
  920. +       } else if(strcmp(name, "intensive cyan") == 0) {
  921. +               strncpy(dest, "\033[1;36m", COLOR_LEN);
  922. +       } else if(strcmp(name, "intensive white") == 0) {
  923. +               strncpy(dest, "\033[1;37m", COLOR_LEN);
  924. +       } else if(strcmp(name, "intensive foreground") == 0) {
  925. +               strncpy(dest, "\033[m\033[1m", COLOR_LEN);
  926. +       } else if(strcmp(name, "none") == 0) {
  927. +               strncpy(dest, "\033[m", COLOR_LEN);
  928. +       } else {
  929. +               ret = 1;
  930. +       }
  931. +       dest[COLOR_LEN] = '\0';
  932. +       return(ret);
  933. +}
  934. +
  935. +void _insert_color(FILE* stream, color_t color)
  936. +{
  937. +       switch(color) {
  938. +               case COLOR_RED:
  939. +                       fprintf(stream, colortab.red);
  940. +                       break;
  941. +               case COLOR_GREEN:
  942. +                       fprintf(stream, colortab.green);
  943. +                       break;
  944. +               case COLOR_YELLOW:
  945. +                       fprintf(stream, colortab.yellow);
  946. +                       break;
  947. +               case COLOR_BLUE:
  948. +                       fprintf(stream, colortab.blue);
  949. +                       break;
  950. +               case COLOR_MAGENTA:
  951. +                       fprintf(stream, colortab.magenta);
  952. +                       break;
  953. +               case COLOR_CYAN:
  954. +                       fprintf(stream, colortab.cyan);
  955. +                       break;
  956. +               case COLOR_WHITE:
  957. +                       fprintf(stream, colortab.white);
  958. +                       break;
  959. +               case COLOR_NONE:
  960. +                       fprintf(stream, colortab.none);
  961. +                       break;
  962. +               default:;
  963. +       }
  964. +}
  965. +
  966. +int _parsecolorconfig(colortab_t* colortab, char* file)
  967. +{
  968. +       _set_color_sequence("intensive red", colortab->red);
  969. +       _set_color_sequence("intensive green", colortab->green);
  970. +       _set_color_sequence("intensive yellow", colortab->yellow);
  971. +       _set_color_sequence("intensive blue", colortab->blue);
  972. +       _set_color_sequence("intensive magenta", colortab->magenta);
  973. +       _set_color_sequence("intensive cyan", colortab->cyan);
  974. +       _set_color_sequence("intensive foreground", colortab->white);
  975. +       _set_color_sequence("none", colortab->none);
  976. +
  977. +       FILE* fp = NULL;
  978. +       int linenum = 0;
  979. +       char line[PATH_MAX+1];
  980. +       char* ptr;
  981. +
  982. +       fp = fopen(file, "r");
  983. +       if(fp == NULL) {
  984. +               pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file);
  985. +               return 1;
  986. +       }
  987. +       while(fgets(line, PATH_MAX, fp)) {
  988. +               linenum++;
  989. +               strtrim(line);
  990. +
  991. +               if(strlen(line) == 0 || line[0] == '#') {
  992. +                       continue;
  993. +               }
  994. +               if((ptr = strchr(line, '#'))) {
  995. +                       *ptr = '\0';
  996. +               }
  997. +
  998. +               char* key = line;
  999. +               ptr = line;
  1000. +               strsep(&ptr, "=");
  1001. +               strtrim(key);
  1002. +               strtrim(ptr);
  1003. +
  1004. +               if(key == NULL) {
  1005. +                       pm_printf(PM_LOG_ERROR, _("config file %s, line %d: syntax error in config file- missing key.\n"),
  1006. +                                       file, linenum);
  1007. +                       return 1;
  1008. +               }
  1009. +               if(strcmp(key, "Red") == 0) {
  1010. +                       if(_set_color_sequence(ptr, colortab->red)) {
  1011. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1012. +                                                       file, linenum, ptr);
  1013. +                       }
  1014. +               } else if(strcmp(key, "Green") == 0) {
  1015. +                       if(_set_color_sequence(ptr, colortab->green)) {
  1016. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1017. +                                                       file, linenum, ptr);
  1018. +                       }
  1019. +               } else if(strcmp(key, "Yellow") == 0) {
  1020. +                       if(_set_color_sequence(ptr, colortab->yellow)) {
  1021. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1022. +                                                       file, linenum, ptr);
  1023. +                       }
  1024. +               } else if(strcmp(key, "Blue") == 0) {
  1025. +                       if(_set_color_sequence(ptr, colortab->blue)) {
  1026. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1027. +                                                       file, linenum, ptr);
  1028. +                       }
  1029. +               } else if(strcmp(key, "Magenta") == 0) {
  1030. +                       if(_set_color_sequence(ptr, colortab->magenta)) {
  1031. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1032. +                                                       file, linenum, ptr);
  1033. +                       }
  1034. +               } else if(strcmp(key, "Cyan") == 0) {
  1035. +                       if(_set_color_sequence(ptr, colortab->cyan)) {
  1036. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1037. +                                                       file, linenum, ptr);
  1038. +                       }
  1039. +               } else if(strcmp(key, "White") == 0) {
  1040. +                       if(_set_color_sequence(ptr, colortab->white)) {
  1041. +                               pm_printf(PM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
  1042. +                                                       file, linenum, ptr);
  1043. +                       }
  1044. +               } else {
  1045. +                       pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"),
  1046. +                                       file, linenum, key);
  1047. +                       return(1);
  1048. +               }
  1049. +       }
  1050. +       return(0);
  1051. +}
  1052. +
  1053. +int parsecolorconfig()
  1054. +{
  1055. +       return(_parsecolorconfig(&colortab, "/etc/pacman.d/color.conf"));
  1056. +}
  1057. +
  1058. +int color_vfprintf(FILE* stream, const colordata_t* colors, const char* format, va_list args)
  1059. +{
  1060. +       int ret = 0;
  1061. +
  1062. +       if(isatty(fileno(stream)) && colors) {
  1063. +               char* msg = NULL;
  1064. +               ret = vasprintf(&msg, format, args);
  1065. +               if(msg == NULL) {
  1066. +                       return(ret);
  1067. +               }
  1068. +
  1069. +               const colordata_t* colorpos = colors;
  1070. +               color_t colorlast = COLOR_NONE;
  1071. +               int len = strlen(msg) + 1;
  1072. +               wchar_t* wcstr = calloc(len, sizeof(wchar_t));
  1073. +               len = mbstowcs(wcstr, msg, len);
  1074. +               free(msg);
  1075. +               const wchar_t *strpos = wcstr;
  1076. +              
  1077. +               while(*strpos) {
  1078. +                       if(colorpos->color != COLOR_END &&
  1079. +                               ((colorpos->separator == SEP_ANY) ||
  1080. +                                (colorpos->separator == SEP_LINE && *strpos == L'\n') ||
  1081. +                                (colorpos->separator == SEP_COLON && (*strpos == L':' || *strpos == L':')))) {
  1082. +                               _insert_color(stream, colorpos->color);
  1083. +                               colorlast = colorpos->color;
  1084. +                               colorpos++;
  1085. +                       }
  1086. +                       fprintf(stream, "%lc", (wint_t)*strpos);
  1087. +                       strpos++;
  1088. +               }
  1089. +               free(wcstr);
  1090. +
  1091. +               if(colorlast != COLOR_NONE) {
  1092. +                       _insert_color(stream, COLOR_NONE);
  1093. +               }
  1094. +       } else {
  1095. +               ret = vfprintf(stream, format, args);
  1096. +       }
  1097. +       return(ret);
  1098. +}
  1099. +
  1100. +int color_fprintf(FILE* stream, const colordata_t* colors, const char* format, ...)
  1101. +{
  1102. +       int ret;
  1103. +       va_list args;
  1104. +       va_start(args, format);
  1105. +       ret = color_vfprintf(stream, colors, format, args);
  1106. +       va_end(args);
  1107. +       return(ret);
  1108. +}
  1109. +
  1110. +int color_printf(const colordata_t* colors, const char* format, ...)
  1111. +{
  1112. +       int ret;
  1113. +       va_list args;
  1114. +       va_start(args, format);
  1115. +       ret = color_vfprintf(stdout, colors, format, args);
  1116. +       va_end(args);
  1117. +       return(ret);
  1118. +}
  1119. +
  1120. +void color_string_display(const colordata_t* colors_title, const char* title, const colordata_t* colors_string, const char* string)
  1121. +{
  1122. +       if(title) {
  1123. +               color_printf(colors_title, "%s ", title);
  1124. +       }
  1125. +       if(string == NULL || string[0] == '\0') {
  1126. +               printf(_("None"));
  1127. +       } else {
  1128. +               color_printf(colors_string, "%s", string);
  1129. +       }
  1130. +       printf("\n");
  1131. +}
  1132. +
  1133. +const colordata_t COLOR_WHITE_ALL[] = {
  1134. +       { SEP_ANY, COLOR_WHITE },
  1135. +       { SEP_LINE, COLOR_NONE },
  1136. +       { SEP_ANY, COLOR_END } };
  1137. +
  1138. +const colordata_t COLOR_GREEN_ALL[] = {
  1139. +       { SEP_ANY, COLOR_GREEN },
  1140. +       { SEP_LINE, COLOR_NONE },
  1141. +       { SEP_ANY, COLOR_END } };
  1142. +
  1143. +const colordata_t COLOR_RED_ALL[] = {
  1144. +       { SEP_ANY, COLOR_RED },
  1145. +       { SEP_LINE, COLOR_NONE },
  1146. +       { SEP_ANY, COLOR_END } };
  1147. +
  1148. +const colordata_t COLOR_BLUE_ALL[] = {
  1149. +       { SEP_ANY, COLOR_BLUE },
  1150. +       { SEP_LINE, COLOR_NONE },
  1151. +       { SEP_ANY, COLOR_END } };
  1152. +
  1153. +const colordata_t COLOR_YELLOW_ALL[] = {
  1154. +       { SEP_ANY, COLOR_YELLOW },
  1155. +       { SEP_LINE, COLOR_NONE },
  1156. +       { SEP_ANY, COLOR_END } };
  1157. +
  1158. +const colordata_t COLOR_MAGENTA_ALL[] = {
  1159. +       { SEP_ANY, COLOR_MAGENTA },
  1160. +       { SEP_LINE, COLOR_NONE },
  1161. +       { SEP_ANY, COLOR_END } };
  1162. +
  1163. +const colordata_t COLOR_CYAN_ALL[] = {
  1164. +       { SEP_ANY, COLOR_CYAN },
  1165. +       { SEP_LINE, COLOR_NONE },
  1166. +       { SEP_ANY, COLOR_END } };
  1167. +
  1168. +const colordata_t COLOR_DOUBLECOLON[] = {
  1169. +       { SEP_ANY, COLOR_BLUE },
  1170. +       { SEP_ANY, COLOR_SAME },
  1171. +       { SEP_ANY, COLOR_WHITE },
  1172. +       { SEP_LINE, COLOR_NONE },
  1173. +       { SEP_ANY, COLOR_END } };
  1174. +
  1175. +const colordata_t COLOR_DOUBLECOLON2[] = {
  1176. +       { SEP_ANY, COLOR_BLUE },
  1177. +       { SEP_ANY, COLOR_SAME },
  1178. +       { SEP_ANY, COLOR_WHITE },
  1179. +       { SEP_LINE, COLOR_NONE },
  1180. +       { SEP_ANY, COLOR_BLUE },
  1181. +       { SEP_ANY, COLOR_SAME },
  1182. +       { SEP_ANY, COLOR_WHITE },
  1183. +       { SEP_LINE, COLOR_NONE },
  1184. +       { SEP_ANY, COLOR_END } };
  1185. +
  1186. +const colordata_t COLOR_WHITE_COLON[] = {
  1187. +       { SEP_ANY, COLOR_WHITE },
  1188. +       { SEP_COLON, COLOR_SAME },
  1189. +       { SEP_ANY, COLOR_NONE },
  1190. +       { SEP_ANY, COLOR_END } };
  1191. +
  1192.  /* vim: set ts=2 sw=2 noet: */
  1193. diff -Naur pacman-3.4.1/src/pacman//util.h pacman-color-3.4.1/src/pacman//util.h
  1194. --- pacman-3.4.1/src/pacman//util.h     2010-06-24 15:23:29.000000000 +0200
  1195. +++ pacman-color-3.4.1/src/pacman//util.h       2010-09-05 23:07:49.695175136 +0200
  1196. @@ -37,6 +37,48 @@
  1197.  /* update speed for the fill_progress based functions */
  1198.  #define UPDATE_SPEED_SEC 0.2f
  1199.  
  1200. +/* pacman-color */
  1201. +typedef enum _separator_t {
  1202. +       SEP_ANY = 0,
  1203. +       SEP_LINE,
  1204. +       SEP_COLON,
  1205. +} separator_t;
  1206. +
  1207. +typedef enum _color_t {
  1208. +       COLOR_END = 0,
  1209. +       COLOR_SAME,
  1210. +       COLOR_RED,
  1211. +       COLOR_GREEN,
  1212. +       COLOR_YELLOW,
  1213. +       COLOR_BLUE,
  1214. +       COLOR_MAGENTA,
  1215. +       COLOR_CYAN,
  1216. +       COLOR_WHITE,
  1217. +       COLOR_NONE,
  1218. +} color_t;
  1219. +
  1220. +typedef struct _colordata_t {
  1221. +       separator_t separator;
  1222. +       color_t color;
  1223. +} colordata_t;
  1224. +
  1225. +extern const colordata_t COLOR_WHITE_ALL[];
  1226. +extern const colordata_t COLOR_GREEN_ALL[];
  1227. +extern const colordata_t COLOR_RED_ALL[];
  1228. +extern const colordata_t COLOR_BLUE_ALL[];
  1229. +extern const colordata_t COLOR_YELLOW_ALL[];
  1230. +extern const colordata_t COLOR_MAGENTA_ALL[];
  1231. +extern const colordata_t COLOR_CYAN_ALL[];
  1232. +extern const colordata_t COLOR_DOUBLECOLON[];
  1233. +extern const colordata_t COLOR_DOUBLECOLON2[];
  1234. +extern const colordata_t COLOR_WHITE_COLON[];
  1235. +
  1236. +int parsecolorconfig();
  1237. +int color_fprintf(FILE* stream, const colordata_t* colors, const char* format, ...) __attribute__((format(printf,3,4)));
  1238. +int color_printf(const colordata_t* colors, const char* format, ...) __attribute__((format(printf,2,3)));
  1239. +int color_vfprintf(FILE* stream, const colordata_t* colors, const char* format, va_list args) __attribute__((format(printf,3,0)));
  1240. +void color_string_display(const colordata_t* colors_title, const char* title, const colordata_t* colors_string, const char* string);
  1241. +
  1242.  int trans_init(pmtransflag_t flags);
  1243.  int trans_release(void);
  1244.  int needs_root(void);
  1245. @@ -49,15 +91,15 @@
  1246.  char *strtrim(char *str);
  1247.  char *strreplace(const char *str, const char *needle, const char *replace);
  1248.  alpm_list_t *strsplit(const char *str, const char splitchar);
  1249. -void string_display(const char *title, const char *string);
  1250. -void list_display(const char *title, const alpm_list_t *list);
  1251. -void list_display_linebreak(const char *title, const alpm_list_t *list);
  1252. +void string_display(const colordata_t *colors_title, const char *title, const char *string);
  1253. +void list_display(const colordata_t *colors_title, const char *title, const alpm_list_t *list);
  1254. +void list_display_linebreak(const colordata_t *colors_title, const char *title, const alpm_list_t *list);
  1255.  void display_targets(const alpm_list_t *pkgs, int install);
  1256.  void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg);
  1257.  void display_optdepends(pmpkg_t *pkg);
  1258.  void print_packages(const alpm_list_t *packages);
  1259. -int yesno(char *fmt, ...);
  1260. -int noyes(char *fmt, ...);
  1261. +int yesno(const colordata_t *colors, char *fmt, ...);
  1262. +int noyes(const colordata_t *colors, char *fmt, ...);
  1263.  int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
  1264.  int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
  1265.  int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));