updated on Sun Jan 15 08:01:04 UTC 2012
[aur-mirror.git] / pacman-color-testing / pacman-color-testing-4.0.1-1.patch
blob38a848a59a98b8424ce9f9a2ec3b01031851ba82
1 diff -Npaur a/src/pacman/callback.c b/src/pacman/callback.c
2 --- a/src/pacman/callback.c 2011-11-15 17:07:16.000000000 +0200
3 +++ b/src/pacman/callback.c 2011-11-22 00:34:58.246461928 +0200
4 @@ -221,16 +221,16 @@ void cb_event(alpm_event_t event, void *
5 printf(_("generating %s with %s... "), (char *)data1, (char *)data2);
6 break;
7 case ALPM_EVENT_DELTA_PATCH_DONE:
8 - printf(_("success!\n"));
9 + color_printf(COLOR_GREEN_ALL, _("success!\n"));
10 break;
11 case ALPM_EVENT_DELTA_PATCH_FAILED:
12 - printf(_("failed.\n"));
13 + color_printf(COLOR_RED_ALL, _("failed.\n"));
14 break;
15 case ALPM_EVENT_SCRIPTLET_INFO:
16 printf("%s", (char *)data1);
17 break;
18 case ALPM_EVENT_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 case ALPM_EVENT_DISKSPACE_START:
23 if(config->noprogressbar) {
24 @@ -264,14 +264,14 @@ void cb_question(alpm_question_t event,
25 switch(event) {
26 case ALPM_QUESTION_INSTALL_IGNOREPKG:
27 if(!config->op_s_downloadonly) {
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 } else {
32 *response = 1;
34 break;
35 case ALPM_QUESTION_REPLACE_PKG:
36 - *response = yesno(_(":: Replace %s with %s/%s?"),
37 + *response = yesno(COLOR_DOUBLECOLON, _(":: Replace %s with %s/%s?"),
38 alpm_pkg_get_name(data1),
39 (char *)data3,
40 alpm_pkg_get_name(data2));
41 @@ -280,12 +280,12 @@ void cb_question(alpm_question_t event,
42 /* data parameters: target package, local package, conflict (strings) */
43 /* print conflict only if it contains new information */
44 if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) {
45 - *response = noyes(_(":: %s and %s are in conflict. Remove %s?"),
46 + *response = noyes(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict. Remove %s?"),
47 (char *)data1,
48 (char *)data2,
49 (char *)data2);
50 } else {
51 - *response = noyes(_(":: %s and %s are in conflict (%s). Remove %s?"),
52 + *response = noyes(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict (%s). Remove %s?"),
53 (char *)data1,
54 (char *)data2,
55 (char *)data3,
56 @@ -302,13 +302,13 @@ void cb_question(alpm_question_t event,
57 (char *)alpm_pkg_get_name(i->data));
58 count++;
60 - printf(_n(
61 + color_printf(COLOR_DOUBLECOLON, _n(
62 ":: The following package cannot be upgraded due to unresolvable dependencies:\n",
63 ":: The following packages cannot be upgraded due to unresolvable dependencies:\n",
64 count));
65 - list_display(" ", namelist);
66 + list_display(NULL, " ", namelist);
67 printf("\n");
68 - *response = noyes(_n(
69 + *response = noyes(NULL, _n(
70 "Do you want to skip the above package for this upgrade?",
71 "Do you want to skip the above packages for this upgrade?",
72 count));
73 @@ -320,7 +320,7 @@ void cb_question(alpm_question_t event,
74 alpm_list_t *providers = (alpm_list_t *)data1;
75 size_t count = alpm_list_count(providers);
76 char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2);
77 - printf(_(":: There are %zd providers available for %s:\n"), count,
78 + color_printf(COLOR_DOUBLECOLON, _(":: There are %zd providers available for %s:\n"), count,
79 depstring);
80 free(depstring);
81 select_display(providers);
82 @@ -329,7 +329,7 @@ void cb_question(alpm_question_t event,
83 break;
84 case ALPM_QUESTION_LOCAL_NEWER:
85 if(!config->op_s_downloadonly) {
86 - *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"),
87 + *response = yesno(COLOR_DOUBLECOLON, _(":: %s-%s: local version is newer. Upgrade anyway?"),
88 alpm_pkg_get_name(data1),
89 alpm_pkg_get_version(data1));
90 } else {
91 @@ -337,7 +337,7 @@ void cb_question(alpm_question_t event,
93 break;
94 case ALPM_QUESTION_CORRUPTED_PKG:
95 - *response = yesno(_(":: File %s is corrupted (%s).\n"
96 + *response = yesno(COLOR_DOUBLECOLON, _(":: File %s is corrupted (%s).\n"
97 "Do you want to delete it?"),
98 (char *)data1,
99 alpm_strerror(*(enum _alpm_errno_t *)data2));
100 @@ -347,7 +347,7 @@ void cb_question(alpm_question_t event,
101 alpm_pgpkey_t *key = data1;
102 char created[12];
103 strftime(created, 12, "%Y-%m-%d", localtime(&(key->created)));
104 - *response = yesno(_(":: Import PGP key %s, \"%s\", created %s?"),
105 + *response = yesno(COLOR_DOUBLECOLON, _(":: Import PGP key %s, \"%s\", created %s?"),
106 key->fingerprint, key->uid, created);
108 break;
109 @@ -481,8 +481,9 @@ void cb_progress(alpm_progress_t event,
113 - printf("(%*ld/%*ld) %ls%-*s", digits, (unsigned long)current,
114 - digits, (unsigned long)howmany, wcstr, padwid, "");
115 + color_printf(COLOR_BLUE_ALL, "(%*ld/%*ld)", digits, (unsigned long)current,
116 + digits, (unsigned long)howmany);
117 + printf(" %ls%-*s", wcstr, padwid, "");
119 free(wcstr);
121 diff -Npaur a/src/pacman/package.c b/src/pacman/package.c
122 --- a/src/pacman/package.c 2011-10-21 18:50:07.000000000 +0300
123 +++ b/src/pacman/package.c 2011-11-22 00:34:58.247461928 +0200
124 @@ -41,7 +41,7 @@
125 * @param deps a list with items of type alpm_depend_t
126 * @return a string list, must be freed
128 -static void deplist_display(const char *title,
129 +static void deplist_display(const colordata_t *colors_title, const char *title,
130 alpm_list_t *deps)
132 alpm_list_t *i, *text = NULL;
133 @@ -49,7 +49,7 @@ static void deplist_display(const char *
134 alpm_depend_t *dep = alpm_list_getdata(i);
135 text = alpm_list_add(text, alpm_dep_compute_string(dep));
137 - list_display(title, text);
138 + list_display(colors_title, title, text);
139 FREELIST(text);
142 @@ -102,65 +102,65 @@ void dump_pkg_full(alpm_pkg_t *pkg, int
144 /* actual output */
145 if(from == PKG_FROM_SYNCDB) {
146 - string_display(_("Repository :"),
147 - alpm_db_get_name(alpm_pkg_get_db(pkg)));
148 + color_string_display(COLOR_WHITE_ALL, _("Repository :"),
149 + COLOR_MAGENTA_ALL, alpm_db_get_name(alpm_pkg_get_db(pkg)));
151 - string_display(_("Name :"), alpm_pkg_get_name(pkg));
152 - string_display(_("Version :"), alpm_pkg_get_version(pkg));
153 - string_display(_("URL :"), alpm_pkg_get_url(pkg));
154 - list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg));
155 - list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
156 - deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
157 - deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
158 - list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
159 + color_string_display(COLOR_WHITE_ALL, _("Name :"), COLOR_WHITE_ALL, alpm_pkg_get_name(pkg));
160 + color_string_display(COLOR_WHITE_ALL, _("Version :"), COLOR_GREEN_ALL, alpm_pkg_get_version(pkg));
161 + color_string_display(COLOR_WHITE_ALL, _("URL :"), COLOR_CYAN_ALL, alpm_pkg_get_url(pkg));
162 + list_display(COLOR_WHITE_ALL, _("Licenses :"), alpm_pkg_get_licenses(pkg));
163 + list_display(COLOR_WHITE_ALL, _("Groups :"), alpm_pkg_get_groups(pkg));
164 + deplist_display(COLOR_WHITE_ALL, _("Provides :"), alpm_pkg_get_provides(pkg));
165 + deplist_display(COLOR_WHITE_ALL, _("Depends On :"), alpm_pkg_get_depends(pkg));
166 + list_display_linebreak(COLOR_WHITE_ALL, _("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
167 if(extra || from == PKG_FROM_LOCALDB) {
168 - list_display(_("Required By :"), requiredby);
169 + list_display(COLOR_WHITE_ALL, _("Required By :"), requiredby);
171 - deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
172 - deplist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
173 + deplist_display(COLOR_WHITE_ALL, _("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
174 + deplist_display(COLOR_WHITE_ALL, _("Replaces :"), alpm_pkg_get_replaces(pkg));
176 size = humanize_size(alpm_pkg_get_size(pkg), 'K', &label);
177 if(from == PKG_FROM_SYNCDB) {
178 - printf(_("Download Size : %6.2f %s\n"), size, label);
179 + color_printf(COLOR_WHITE_COLON, _("Download Size : %6.2f %s\n"), size, label);
180 } else if(from == PKG_FROM_FILE) {
181 - printf(_("Compressed Size: %6.2f %s\n"), size, label);
182 + color_printf(COLOR_WHITE_COLON, _("Compressed Size: %6.2f %s\n"), size, label);
185 size = humanize_size(alpm_pkg_get_isize(pkg), 'K', &label);
186 - printf(_("Installed Size : %6.2f %s\n"), size, label);
187 + color_printf(COLOR_WHITE_COLON, _("Installed Size : %6.2f %s\n"), size, label);
189 - string_display(_("Packager :"), alpm_pkg_get_packager(pkg));
190 - string_display(_("Architecture :"), alpm_pkg_get_arch(pkg));
191 - string_display(_("Build Date :"), bdatestr);
192 + string_display(COLOR_WHITE_ALL, _("Packager :"), alpm_pkg_get_packager(pkg));
193 + string_display(COLOR_WHITE_ALL, _("Architecture :"), alpm_pkg_get_arch(pkg));
194 + string_display(COLOR_WHITE_ALL, _("Build Date :"), bdatestr);
195 if(from == PKG_FROM_LOCALDB) {
196 - string_display(_("Install Date :"), idatestr);
197 - string_display(_("Install Reason :"), reason);
198 + string_display(COLOR_WHITE_ALL, _("Install Date :"), idatestr);
199 + string_display(COLOR_WHITE_ALL, _("Install Reason :"), reason);
201 if(from == PKG_FROM_FILE || from == PKG_FROM_LOCALDB) {
202 - string_display(_("Install Script :"),
203 + string_display(COLOR_WHITE_ALL, _("Install Script :"),
204 alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
207 if(from == PKG_FROM_SYNCDB) {
208 - string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg));
209 - string_display(_("SHA256 Sum :"), alpm_pkg_get_sha256sum(pkg));
210 - string_display(_("Signatures :"),
211 + string_display(COLOR_WHITE_ALL, _("MD5 Sum :"), alpm_pkg_get_md5sum(pkg));
212 + string_display(COLOR_WHITE_ALL, _("SHA256 Sum :"), alpm_pkg_get_sha256sum(pkg));
213 + string_display(COLOR_WHITE_ALL, _("Signatures :"),
214 alpm_pkg_get_base64_sig(pkg) ? _("Yes") : _("None"));
216 if(from == PKG_FROM_FILE) {
217 alpm_siglist_t siglist;
218 int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
219 if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
220 - string_display(_("Signatures :"), _("None"));
221 + string_display(COLOR_WHITE_ALL, _("Signatures :"), _("None"));
222 } else if(err) {
223 - string_display(_("Signatures :"),
224 + string_display(COLOR_WHITE_ALL, _("Signatures :"),
225 alpm_strerror(alpm_errno(config->handle)));
226 } else {
227 signature_display(_("Signatures :"), &siglist);
229 alpm_siglist_cleanup(&siglist);
231 - string_display(_("Description :"), alpm_pkg_get_desc(pkg));
232 + string_display(COLOR_WHITE_ALL, _("Description :"), alpm_pkg_get_desc(pkg));
234 /* Print additional package info if info flag passed more than once */
235 if(from == PKG_FROM_LOCALDB && extra) {
236 @@ -219,7 +219,7 @@ void dump_pkg_backups(alpm_pkg_t *pkg)
238 alpm_list_t *i;
239 const char *root = alpm_option_get_root(config->handle);
240 - printf(_("Backup Files:\n"));
241 + color_printf(COLOR_WHITE_ALL, _("Backup Files:\n"));
242 if(alpm_pkg_get_backup(pkg)) {
243 /* package has backup files, so print them */
244 for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
245 @@ -252,7 +252,8 @@ void dump_pkg_files(alpm_pkg_t *pkg, int
246 for(i = 0; i < pkgfiles->count; i++) {
247 const alpm_file_t *file = pkgfiles->files + i;
248 if(!quiet) {
249 - printf("%s %s%s\n", pkgname, root, file->name);
250 + color_printf(COLOR_WHITE_ALL, "%s", pkgname);
251 + printf(" %s%s\n", root, file->name);
252 } else {
253 printf("%s%s\n", root, file->name);
255 diff -Npaur a/src/pacman/pacman.c b/src/pacman/pacman.c
256 --- a/src/pacman/pacman.c 2011-10-21 18:40:57.000000000 +0300
257 +++ b/src/pacman/pacman.c 2011-11-22 00:34:58.247461928 +0200
258 @@ -221,11 +221,23 @@ static void usage(int op, const char * c
260 static void version(void)
262 + color_printf(COLOR_YELLOW_ALL, " .--. ");
263 + printf(" ");
264 + color_printf(COLOR_RED_ALL, " .---. ");
265 + printf(" Pacman-color v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version());
266 + color_printf(COLOR_YELLOW_ALL, "/ _.-'");
267 + color_printf(COLOR_WHITE_ALL, " .-. .-");
268 + color_printf(COLOR_RED_ALL, "|O O |");
269 + printf(" Copyright (C) 2006-2011 Pacman Development Team\n");
270 + color_printf(COLOR_YELLOW_ALL, "\\ '-.");
271 + color_printf(COLOR_WHITE_ALL, " '-' '-");
272 + color_printf(COLOR_RED_ALL, "|~~~ |");
273 + printf(" Copyright (C) 2002-2006 Judd Vinet\n");
274 + color_printf(COLOR_YELLOW_ALL, " '--' ");
275 + printf(" ");
276 + color_printf(COLOR_RED_ALL, "|.-.-.|");
277 + printf(" Colored by vogo <vogo(at)seznam(dot)cz>\n");
278 printf("\n");
279 - printf(" .--. Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version());
280 - printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2011 Pacman Development Team\n");
281 - printf("\\ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet\n");
282 - printf(" '--'\n");
283 printf(_(" This program may be freely redistributed under\n"
284 " the terms of the GNU General Public License.\n"));
285 printf("\n");
286 @@ -799,6 +811,7 @@ int main(int argc, char *argv[])
288 /* init config data */
289 config = config_new();
290 + parsecolorconfig();
292 /* disable progressbar if the output is redirected */
293 if(!isatty(1)) {
294 @@ -900,18 +913,18 @@ int main(int argc, char *argv[])
296 if(config->verbose > 0) {
297 alpm_list_t *i;
298 - printf("Root : %s\n", alpm_option_get_root(config->handle));
299 - printf("Conf File : %s\n", config->configfile);
300 - printf("DB Path : %s\n", alpm_option_get_dbpath(config->handle));
301 - printf("Cache Dirs: ");
302 + string_display(COLOR_WHITE_ALL, "Root :", alpm_option_get_root(config->handle));
303 + string_display(COLOR_WHITE_ALL, "Conf File :", config->configfile);
304 + string_display(COLOR_WHITE_ALL, "DB Path :", alpm_option_get_dbpath(config->handle));
305 + color_printf(COLOR_WHITE_ALL, "Cache Dirs: ");
306 for(i = alpm_option_get_cachedirs(config->handle); i; i = alpm_list_next(i)) {
307 printf("%s ", (char *)alpm_list_getdata(i));
309 printf("\n");
310 - printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle));
311 - printf("Log File : %s\n", alpm_option_get_logfile(config->handle));
312 - printf("GPG Dir : %s\n", alpm_option_get_gpgdir(config->handle));
313 - list_display("Targets :", pm_targets);
314 + string_display(COLOR_WHITE_ALL, "Lock File :", alpm_option_get_lockfile(config->handle));
315 + string_display(COLOR_WHITE_ALL, "Log File :", alpm_option_get_logfile(config->handle));
316 + string_display(COLOR_WHITE_ALL, "GPG Dir :", alpm_option_get_gpgdir(config->handle));
317 + list_display(COLOR_WHITE_ALL, "Targets :", pm_targets);
320 /* Log commandline */
321 diff -Npaur a/src/pacman/query.c b/src/pacman/query.c
322 --- a/src/pacman/query.c 2011-10-21 18:40:57.000000000 +0300
323 +++ b/src/pacman/query.c 2011-11-22 00:34:58.248461928 +0200
324 @@ -266,7 +266,9 @@ static int query_search(alpm_list_t *tar
325 alpm_pkg_t *pkg = alpm_list_getdata(i);
327 if(!config->quiet) {
328 - printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
329 + color_printf(COLOR_MAGENTA_ALL, "local/");
330 + color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
331 + color_printf(COLOR_GREEN_ALL, "%s", alpm_pkg_get_version(pkg));
332 } else {
333 printf("%s", alpm_pkg_get_name(pkg));
335 @@ -275,16 +277,11 @@ static int query_search(alpm_list_t *tar
336 if(!config->quiet) {
337 if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
338 alpm_list_t *k;
339 - printf(" (");
340 + color_printf(COLOR_BLUE_ALL, " (");
341 for(k = grp; k; k = alpm_list_next(k)) {
342 const char *group = alpm_list_getdata(k);
343 - printf("%s", group);
344 - if(alpm_list_next(k)) {
345 - /* only print a spacer if there are more groups */
346 - printf(" ");
348 + color_printf(COLOR_BLUE_ALL, "%s%s", group, (alpm_list_next(k) ? " " : ")"));
350 - printf(")");
353 /* we need a newline and initial indent first */
354 @@ -315,7 +312,8 @@ static int query_group(alpm_list_t *targ
356 for(p = grp->packages; p; p = alpm_list_next(p)) {
357 alpm_pkg_t *pkg = alpm_list_getdata(p);
358 - printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
359 + color_printf(COLOR_BLUE_ALL, "%s ", grp->name);
360 + color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(pkg));
363 } else {
364 @@ -327,8 +325,8 @@ static int query_group(alpm_list_t *targ
365 const alpm_list_t *p;
366 for(p = grp->packages; p; p = alpm_list_next(p)) {
367 if(!config->quiet) {
368 - printf("%s %s\n", grpname,
369 - alpm_pkg_get_name(alpm_list_getdata(p)));
370 + color_printf(COLOR_BLUE_ALL, "%s ", grpname);
371 + color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
372 } else {
373 printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
375 @@ -478,7 +476,8 @@ static int display(alpm_pkg_t *pkg)
376 if(!config->op_q_info && !config->op_q_list
377 && !config->op_q_changelog && !config->op_q_check) {
378 if(!config->quiet) {
379 - printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
380 + color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
381 + color_printf(COLOR_GREEN_ALL, "%s\n", alpm_pkg_get_version(pkg));
382 } else {
383 printf("%s\n", alpm_pkg_get_name(pkg));
385 diff -Npaur a/src/pacman/remove.c b/src/pacman/remove.c
386 --- a/src/pacman/remove.c 2011-10-21 18:40:57.000000000 +0300
387 +++ b/src/pacman/remove.c 2011-11-22 00:34:58.248461928 +0200
388 @@ -111,14 +111,14 @@ int pacman_remove(alpm_list_t *targets)
389 case ALPM_ERR_PKG_INVALID_ARCH:
390 for(i = data; i; i = alpm_list_next(i)) {
391 char *pkg = alpm_list_getdata(i);
392 - printf(_(":: package %s does not have a valid architecture\n"), pkg);
393 + color_printf(COLOR_DOUBLECOLON, _(":: package %s does not have a valid architecture\n"), pkg);
395 break;
396 case ALPM_ERR_UNSATISFIED_DEPS:
397 for(i = data; i; i = alpm_list_next(i)) {
398 alpm_depmissing_t *miss = alpm_list_getdata(i);
399 char *depstring = alpm_dep_compute_string(miss->depend);
400 - printf(_(":: %s: requires %s\n"), miss->target, depstring);
401 + color_printf(COLOR_DOUBLECOLON, _(":: %s: requires %s\n"), miss->target, depstring);
402 free(depstring);
404 break;
405 @@ -140,7 +140,7 @@ int pacman_remove(alpm_list_t *targets)
406 holdpkg = 1;
409 - if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
410 + if(holdpkg && (noyes(NULL, _("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
411 retval = 1;
412 goto cleanup;
414 @@ -160,7 +160,7 @@ int pacman_remove(alpm_list_t *targets)
415 /* print targets and ask user confirmation */
416 display_targets();
417 printf("\n");
418 - if(yesno(_("Do you want to remove these packages?")) == 0) {
419 + if(yesno(NULL, _("Do you want to remove these packages?")) == 0) {
420 retval = 1;
421 goto cleanup;
423 diff -Npaur a/src/pacman/sync.c b/src/pacman/sync.c
424 --- a/src/pacman/sync.c 2011-11-15 16:29:05.000000000 +0200
425 +++ b/src/pacman/sync.c 2011-11-22 00:34:58.249461928 +0200
426 @@ -103,7 +103,7 @@ static int sync_cleandb(const char *dbpa
427 /* We have a database that doesn't match any syncdb.
428 * Ask the user if he wants to remove it. */
429 if(!found) {
430 - if(!yesno(_("Do you want to remove %s?"), path)) {
431 + if(!yesno(NULL, _("Do you want to remove %s?"), path)) {
432 continue;
435 @@ -126,8 +126,8 @@ static int sync_cleandb_all(void)
436 int ret = 0;
438 dbpath = alpm_option_get_dbpath(config->handle);
439 - printf(_("Database directory: %s\n"), dbpath);
440 - if(!yesno(_("Do you want to remove unused repositories?"))) {
441 + color_printf(COLOR_WHITE_COLON, _("Database directory: %s\n"), dbpath);
442 + if(!yesno(NULL, _("Do you want to remove unused repositories?"))) {
443 return 0;
445 /* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/.
446 @@ -155,7 +155,7 @@ static int sync_cleancache(int level)
447 int ret = 0;
449 for(i = cachedirs; i; i = alpm_list_next(i)) {
450 - printf(_("Cache directory: %s\n"), (char *)alpm_list_getdata(i));
451 + color_printf(COLOR_WHITE_COLON, _("Cache directory: %s\n"), (char *)alpm_list_getdata(i));
454 if(!config->cleanmethod) {
455 @@ -164,19 +164,19 @@ static int sync_cleancache(int level)
458 if(level == 1) {
459 - printf(_("Packages to keep:\n"));
460 + color_printf(COLOR_WHITE_COLON, _("Packages to keep:\n"));
461 if(config->cleanmethod & PM_CLEAN_KEEPINST) {
462 printf(_(" All locally installed packages\n"));
464 if(config->cleanmethod & PM_CLEAN_KEEPCUR) {
465 printf(_(" All current sync database packages\n"));
467 - if(!yesno(_("Do you want to remove all other packages from cache?"))) {
468 + if(!yesno(NULL, _("Do you want to remove all other packages from cache?"))) {
469 return 0;
471 printf(_("removing old packages from cache...\n"));
472 } else {
473 - if(!noyes(_("Do you want to remove ALL files from cache?"))) {
474 + if(!noyes(NULL, _("Do you want to remove ALL files from cache?"))) {
475 return 0;
477 printf(_("removing all files from cache...\n"));
478 @@ -226,7 +226,7 @@ static int sync_cleancache(int level)
479 * load of the package, just the metadata. */
480 if(alpm_pkg_load(config->handle, path, 0, 0, &localpkg) != 0
481 || localpkg == NULL) {
482 - if(yesno(_("File %s does not seem to be a valid package, remove it?"),
483 + if(yesno(NULL, _("File %s does not seem to be a valid package, remove it?"),
484 path)) {
485 if(localpkg) {
486 alpm_pkg_free(localpkg);
487 @@ -321,9 +321,9 @@ static void print_installed(alpm_db_t *d
488 if(lpkg) {
489 const char *lpkgver = alpm_pkg_get_version(lpkg);
490 if(strcmp(lpkgver,pkgver) == 0) {
491 - printf(" [%s]", _("installed"));
492 + color_printf(COLOR_CYAN_ALL, " [%s]", _("installed"));
493 } else {
494 - printf(" [%s: %s]", _("installed"), lpkgver);
495 + color_printf(COLOR_CYAN_ALL, " [%s: %s]", _("installed"), lpkgver);
499 @@ -356,8 +356,9 @@ static int sync_search(alpm_list_t *sync
500 alpm_pkg_t *pkg = alpm_list_getdata(j);
502 if(!config->quiet) {
503 - printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
504 - alpm_pkg_get_version(pkg));
505 + color_printf(COLOR_MAGENTA_ALL, "%s/", alpm_db_get_name(db));
506 + color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
507 + color_printf(COLOR_GREEN_ALL, "%s", alpm_pkg_get_version(pkg));
508 } else {
509 printf("%s", alpm_pkg_get_name(pkg));
511 @@ -365,16 +366,11 @@ static int sync_search(alpm_list_t *sync
512 if(!config->quiet) {
513 if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
514 alpm_list_t *k;
515 - printf(" (");
516 + color_printf(COLOR_BLUE_ALL, " (");
517 for(k = grp; k; k = alpm_list_next(k)) {
518 const char *group = alpm_list_getdata(k);
519 - printf("%s", group);
520 - if(alpm_list_next(k)) {
521 - /* only print a spacer if there are more groups */
522 - printf(" ");
524 + color_printf(COLOR_BLUE_ALL, "%s%s", group, (alpm_list_next(k) ? " " : ")"));
526 - printf(")");
529 print_installed(db_local, pkg);
530 @@ -409,8 +405,8 @@ static int sync_group(int level, alpm_li
531 /* get names of packages in group */
532 for(k = grp->packages; k; k = alpm_list_next(k)) {
533 if(!config->quiet) {
534 - printf("%s %s\n", grpname,
535 - alpm_pkg_get_name(alpm_list_getdata(k)));
536 + color_printf(COLOR_BLUE_ALL, "%s ", grpname);
537 + color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
538 } else {
539 printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
541 @@ -427,8 +423,8 @@ static int sync_group(int level, alpm_li
543 if(level > 1) {
544 for(k = grp->packages; k; k = alpm_list_next(k)) {
545 - printf("%s %s\n", grp->name,
546 - alpm_pkg_get_name(alpm_list_getdata(k)));
547 + color_printf(COLOR_BLUE_ALL, "%s ", grp->name);
548 + color_printf(COLOR_WHITE_ALL, "%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
550 } else {
551 /* print grp names only, no package names */
552 @@ -546,8 +542,9 @@ static int sync_list(alpm_list_t *syncs,
553 alpm_pkg_t *pkg = alpm_list_getdata(j);
555 if(!config->quiet) {
556 - printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
557 - alpm_pkg_get_version(pkg));
558 + color_printf(COLOR_MAGENTA_ALL, "%s ", alpm_db_get_name(db));
559 + color_printf(COLOR_WHITE_ALL, "%s ", alpm_pkg_get_name(pkg));
560 + color_printf(COLOR_GREEN_ALL, "%s\n", alpm_pkg_get_version(pkg));
561 print_installed(db_local, pkg);
562 printf("\n");
563 } else {
564 @@ -630,7 +627,7 @@ static int process_group(alpm_list_t *db
567 if(config->print == 0) {
568 - printf(_(":: There are %d members in group %s:\n"), count,
569 + color_printf(COLOR_DOUBLECOLON, _(":: There are %d members in group %s:\n"), count,
570 group);
571 select_display(pkgs);
572 char *array = malloc(count);
573 @@ -747,7 +744,7 @@ static int sync_trans(alpm_list_t *targe
576 if(config->op_s_upgrade) {
577 - printf(_(":: Starting full system upgrade...\n"));
578 + color_printf(COLOR_DOUBLECOLON, _(":: Starting full system upgrade...\n"));
579 alpm_logaction(config->handle, "starting full system upgrade\n");
580 if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) {
581 pm_printf(ALPM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle)));
582 @@ -773,14 +770,14 @@ int sync_prepare_execute(void)
583 case ALPM_ERR_PKG_INVALID_ARCH:
584 for(i = data; i; i = alpm_list_next(i)) {
585 char *pkg = alpm_list_getdata(i);
586 - printf(_(":: package %s does not have a valid architecture\n"), pkg);
587 + color_printf(COLOR_DOUBLECOLON, _(":: package %s does not have a valid architecture\n"), pkg);
589 break;
590 case ALPM_ERR_UNSATISFIED_DEPS:
591 for(i = data; i; i = alpm_list_next(i)) {
592 alpm_depmissing_t *miss = alpm_list_getdata(i);
593 char *depstring = alpm_dep_compute_string(miss->depend);
594 - printf(_(":: %s: requires %s\n"), miss->target, depstring);
595 + color_printf(COLOR_DOUBLECOLON, _(":: %s: requires %s\n"), miss->target, depstring);
596 free(depstring);
598 break;
599 @@ -789,11 +786,11 @@ int sync_prepare_execute(void)
600 alpm_conflict_t *conflict = alpm_list_getdata(i);
601 /* only print reason if it contains new information */
602 if(conflict->reason->mod == ALPM_DEP_MOD_ANY) {
603 - printf(_(":: %s and %s are in conflict\n"),
604 + color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict\n"),
605 conflict->package1, conflict->package2);
606 } else {
607 char *reason = alpm_dep_compute_string(conflict->reason);
608 - printf(_(":: %s and %s are in conflict (%s)\n"),
609 + color_printf(COLOR_DOUBLECOLON, _(":: %s and %s are in conflict (%s)\n"),
610 conflict->package1, conflict->package2, reason);
611 free(reason);
613 @@ -826,9 +823,9 @@ int sync_prepare_execute(void)
615 int confirm;
616 if(config->op_s_downloadonly) {
617 - confirm = yesno(_("Proceed with download?"));
618 + confirm = yesno(NULL, _("Proceed with download?"));
619 } else {
620 - confirm = yesno(_("Proceed with installation?"));
621 + confirm = yesno(NULL, _("Proceed with installation?"));
623 if(!confirm) {
624 goto cleanup;
625 @@ -848,7 +845,7 @@ int sync_prepare_execute(void)
626 conflict->file, conflict->target, conflict->ctarget);
627 break;
628 case ALPM_FILECONFLICT_FILESYSTEM:
629 - printf(_("%s: %s exists in filesystem\n"),
630 + color_printf(COLOR_WHITE_COLON, _("%s: %s exists in filesystem\n"),
631 conflict->target, conflict->file);
632 break;
634 @@ -867,7 +864,7 @@ int sync_prepare_execute(void)
635 break;
637 /* TODO: stderr? */
638 - printf(_("Errors occurred, no packages were upgraded.\n"));
639 + color_printf(COLOR_RED_ALL, _("Errors occurred, no packages were upgraded.\n"));
640 retval = 1;
641 goto cleanup;
643 @@ -915,7 +912,7 @@ int pacman_sync(alpm_list_t *targets)
645 if(config->op_s_sync) {
646 /* grab a fresh package list */
647 - printf(_(":: Synchronizing package databases...\n"));
648 + color_printf(COLOR_DOUBLECOLON, _(":: Synchronizing package databases...\n"));
649 alpm_logaction(config->handle, "synchronizing package lists\n");
650 if(!sync_synctree(config->op_s_sync, sync_dbs)) {
651 return 1;
652 @@ -968,9 +965,9 @@ int pacman_sync(alpm_list_t *targets)
653 alpm_list_t *tmp = NULL;
654 if(config->op_s_upgrade || (tmp = alpm_list_diff(targets, packages, (alpm_list_fn_cmp)strcmp))) {
655 alpm_list_free(tmp);
656 - printf(_(":: The following packages should be upgraded first :\n"));
657 - list_display(" ", packages);
658 - if(yesno(_(":: Do you want to cancel the current operation\n"
659 + color_printf(COLOR_DOUBLECOLON, _(":: The following packages should be upgraded first :\n"));
660 + list_display(NULL, " ", packages);
661 + if(yesno(COLOR_DOUBLECOLON2, _(":: Do you want to cancel the current operation\n"
662 ":: and upgrade these packages now?"))) {
663 FREELIST(targs);
664 targs = packages;
665 diff -Npaur a/src/pacman/util.c b/src/pacman/util.c
666 --- a/src/pacman/util.c 2011-11-21 05:24:39.000000000 +0200
667 +++ b/src/pacman/util.c 2011-11-22 00:34:58.250461929 +0200
668 @@ -48,6 +48,20 @@
669 #include "conf.h"
670 #include "callback.h"
672 +#define COLOR_LEN 8
674 +typedef struct __colortab_t {
675 + char red[COLOR_LEN + 1];
676 + char green[COLOR_LEN + 1];
677 + char yellow[COLOR_LEN + 1];
678 + char blue[COLOR_LEN + 1];
679 + char magenta[COLOR_LEN + 1];
680 + char cyan[COLOR_LEN + 1];
681 + char white[COLOR_LEN + 1];
682 + char none[COLOR_LEN + 1];
683 +} colortab_t;
685 +static colortab_t colortab;
687 int trans_init(alpm_transflag_t flags, int check_valid)
689 @@ -472,10 +486,10 @@ static size_t string_length(const char *
690 return len;
693 -void string_display(const char *title, const char *string)
694 +void string_display(const colordata_t *colors_title, const char *title, const char *string)
696 if(title) {
697 - printf("%s ", title);
698 + color_printf(colors_title, "%s ", title);
700 if(string == NULL || string[0] == '\0') {
701 printf(_("None"));
702 @@ -608,14 +622,14 @@ int table_display(const char *title, con
703 return 0;
706 -void list_display(const char *title, const alpm_list_t *list)
707 +void list_display(const colordata_t *colors_title, const char *title, const alpm_list_t *list)
709 const alpm_list_t *i;
710 size_t len = 0;
712 if(title) {
713 len = string_length(title) + 1;
714 - printf("%s ", title);
715 + color_printf(colors_title, "%s ", title);
718 if(!list) {
719 @@ -649,13 +663,13 @@ void list_display(const char *title, con
723 -void list_display_linebreak(const char *title, const alpm_list_t *list)
724 +void list_display_linebreak(const colordata_t *colors_title, const char *title, const alpm_list_t *list)
726 size_t len = 0;
728 if(title) {
729 len = string_length(title) + 1;
730 - printf("%s ", title);
731 + color_printf(colors_title, "%s ", title);
734 if(!list) {
735 @@ -872,11 +886,11 @@ static void _display_targets(alpm_list_t
736 alpm_list_t *header = create_verbose_header(show_dl_size);
737 if(table_display(str, header, rows) != 0) {
738 /* fallback to list display if table wouldn't fit */
739 - list_display(str, names);
740 + list_display(COLOR_YELLOW_ALL, str, names);
742 alpm_list_free(header);
743 } else {
744 - list_display(str, names);
745 + list_display(COLOR_YELLOW_ALL, str, names);
747 printf("\n");
749 @@ -891,21 +905,21 @@ static void _display_targets(alpm_list_t
751 if(dlsize > 0 || config->op_s_downloadonly) {
752 size = humanize_size(dlsize, 'M', &label);
753 - printf(_("Total Download Size: %.2f %s\n"), size, label);
754 + color_printf(COLOR_WHITE_COLON, _("Total Download Size: %.2f %s\n"), size, label);
756 if(!config->op_s_downloadonly) {
757 if(isize > 0) {
758 size = humanize_size(isize, 'M', &label);
759 - printf(_("Total Installed Size: %.2f %s\n"), size, label);
760 + color_printf(COLOR_WHITE_COLON, _("Total Installed Size: %.2f %s\n"), size, label);
762 if(rsize > 0 && isize == 0) {
763 size = humanize_size(rsize, 'M', &label);
764 - printf(_("Total Removed Size: %.2f %s\n"), size, label);
765 + color_printf(COLOR_WHITE_COLON, _("Total Removed Size: %.2f %s\n"), size, label);
767 /* only show this net value if different from raw installed size */
768 if(isize > 0 && rsize > 0) {
769 size = humanize_size(isize - rsize, 'M', &label);
770 - printf(_("Net Upgrade Size: %.2f %s\n"), size, label);
771 + color_printf(COLOR_WHITE_COLON, _("Net Upgrade Size: %.2f %s\n"), size, label);
775 @@ -1101,7 +1115,7 @@ void display_new_optdepends(alpm_pkg_t *
776 alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
777 if(optdeps) {
778 printf(_("New optional dependencies for %s\n"), alpm_pkg_get_name(newpkg));
779 - list_display_linebreak(" ", optdeps);
780 + list_display_linebreak(NULL, " ", optdeps);
782 alpm_list_free(optdeps);
784 @@ -1111,7 +1125,7 @@ void display_optdepends(alpm_pkg_t *pkg)
785 alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
786 if(optdeps) {
787 printf(_("Optional dependencies for %s\n"), alpm_pkg_get_name(pkg));
788 - list_display_linebreak(" ", optdeps);
789 + list_display_linebreak(NULL, " ", optdeps);
793 @@ -1119,9 +1133,9 @@ static void display_repo_list(const char
795 const char *prefix= " ";
797 - printf(":: ");
798 - printf(_("Repository %s\n"), dbname);
799 - list_display(prefix, list);
800 + color_printf(COLOR_BLUE_ALL, ":: ");
801 + color_printf(COLOR_WHITE_ALL, _("Repository %s\n"), dbname);
802 + list_display(NULL, prefix, list);
805 void select_display(const alpm_list_t *pkglist)
806 @@ -1340,7 +1354,7 @@ int select_question(int count)
809 /* presents a prompt and gets a Y/N answer */
810 -static int question(short preset, char *fmt, va_list args)
811 +static int question(const colordata_t *colors, short preset, char *fmt, va_list args)
813 char response[32];
814 FILE *stream;
815 @@ -1356,7 +1370,7 @@ static int question(short preset, char *
816 fflush(stdout);
817 fflush(stderr);
819 - vfprintf(stream, fmt, args);
820 + color_vfprintf(stream, colors, fmt, args);
822 if(preset) {
823 fprintf(stream, " %s ", _("[Y/n]"));
824 @@ -1387,25 +1401,25 @@ static int question(short preset, char *
825 return 0;
828 -int yesno(char *fmt, ...)
829 +int yesno(const colordata_t *colors, char *fmt, ...)
831 int ret;
832 va_list args;
834 va_start(args, fmt);
835 - ret = question(1, fmt, args);
836 + ret = question(colors, 1, fmt, args);
837 va_end(args);
839 return ret;
842 -int noyes(char *fmt, ...)
843 +int noyes(const colordata_t *colors, char *fmt, ...)
845 int ret;
846 va_list args;
848 va_start(args, fmt);
849 - ret = question(0, fmt, args);
850 + ret = question(colors, 0, fmt, args);
851 va_end(args);
853 return ret;
854 @@ -1454,22 +1468,42 @@ int pm_vasprintf(char **string, alpm_log
855 ret = vasprintf(&msg, format, args);
857 /* print a prefix to the message */
858 - switch(level) {
859 - case ALPM_LOG_ERROR:
860 - pm_asprintf(string, _("error: %s"), msg);
861 - break;
862 - case ALPM_LOG_WARNING:
863 - pm_asprintf(string, _("warning: %s"), msg);
864 - break;
865 - case ALPM_LOG_DEBUG:
866 - pm_asprintf(string, "debug: %s", msg);
867 - break;
868 - case ALPM_LOG_FUNCTION:
869 - pm_asprintf(string, "function: %s", msg);
870 - break;
871 - default:
872 - pm_asprintf(string, "%s", msg);
873 - break;
874 + if(isatty(fileno(stdout))) {
875 + switch(level) {
876 + case ALPM_LOG_ERROR:
877 + pm_asprintf(string, "%s%s%s%s", colortab.red, _("error: "), colortab.none, msg);
878 + break;
879 + case ALPM_LOG_WARNING:
880 + pm_asprintf(string, "%s%s%s%s", colortab.yellow, _("warning: "), colortab.none, msg);
881 + break;
882 + case ALPM_LOG_DEBUG:
883 + pm_asprintf(string, "debug: %s", msg);
884 + break;
885 + case ALPM_LOG_FUNCTION:
886 + pm_asprintf(string, "function: %s", msg);
887 + break;
888 + default:
889 + pm_asprintf(string, "%s", msg);
890 + break;
892 + } else {
893 + switch(level) {
894 + case ALPM_LOG_ERROR:
895 + pm_asprintf(string, _("error: %s"), msg);
896 + break;
897 + case ALPM_LOG_WARNING:
898 + pm_asprintf(string, _("warning: %s"), msg);
899 + break;
900 + case ALPM_LOG_DEBUG:
901 + pm_asprintf(string, "debug: %s", msg);
902 + break;
903 + case ALPM_LOG_FUNCTION:
904 + pm_asprintf(string, "function: %s", msg);
905 + break;
906 + default:
907 + pm_asprintf(string, "%s", msg);
908 + break;
911 free(msg);
913 @@ -1504,10 +1538,10 @@ int pm_vfprintf(FILE *stream, alpm_logle
914 /* print a prefix to the message */
915 switch(level) {
916 case ALPM_LOG_ERROR:
917 - fprintf(stream, _("error: "));
918 + color_fprintf(stream, COLOR_RED_ALL, _("error: "));
919 break;
920 case ALPM_LOG_WARNING:
921 - fprintf(stream, _("warning: "));
922 + color_fprintf(stream, COLOR_YELLOW_ALL, _("warning: "));
923 break;
924 case ALPM_LOG_DEBUG:
925 fprintf(stream, "debug: ");
926 @@ -1546,4 +1580,310 @@ char *strndup(const char *s, size_t n)
928 #endif
930 +/* pacman-color */
932 +int _set_color_sequence(const char* name, char* dest)
934 + int ret = 0;
936 + if(strcmp(name, "black") == 0) {
937 + strncpy(dest, "\033[0;30m", COLOR_LEN);
938 + } else if(strcmp(name, "red") == 0) {
939 + strncpy(dest, "\033[0;31m", COLOR_LEN);
940 + } else if(strcmp(name, "green") == 0) {
941 + strncpy(dest, "\033[0;32m", COLOR_LEN);
942 + } else if(strcmp(name, "yellow") == 0) {
943 + strncpy(dest, "\033[0;33m", COLOR_LEN);
944 + } else if(strcmp(name, "blue") == 0) {
945 + strncpy(dest, "\033[0;34m", COLOR_LEN);
946 + } else if(strcmp(name, "magenta") == 0) {
947 + strncpy(dest, "\033[0;35m", COLOR_LEN);
948 + } else if(strcmp(name, "cyan") == 0) {
949 + strncpy(dest, "\033[0;36m", COLOR_LEN);
950 + } else if(strcmp(name, "white") == 0) {
951 + strncpy(dest, "\033[0;37m", COLOR_LEN);
952 + } else if(strcmp(name, "gray") == 0) {
953 + strncpy(dest, "\033[1;30m", COLOR_LEN);
954 + } else if(strcmp(name, "intensive red") == 0) {
955 + strncpy(dest, "\033[1;31m", COLOR_LEN);
956 + } else if(strcmp(name, "intensive green") == 0) {
957 + strncpy(dest, "\033[1;32m", COLOR_LEN);
958 + } else if(strcmp(name, "intensive yellow") == 0) {
959 + strncpy(dest, "\033[1;33m", COLOR_LEN);
960 + } else if(strcmp(name, "intensive blue") == 0) {
961 + strncpy(dest, "\033[1;34m", COLOR_LEN);
962 + } else if(strcmp(name, "intensive magenta") == 0) {
963 + strncpy(dest, "\033[1;35m", COLOR_LEN);
964 + } else if(strcmp(name, "intensive cyan") == 0) {
965 + strncpy(dest, "\033[1;36m", COLOR_LEN);
966 + } else if(strcmp(name, "intensive white") == 0) {
967 + strncpy(dest, "\033[1;37m", COLOR_LEN);
968 + } else if(strcmp(name, "intensive foreground") == 0) {
969 + strncpy(dest, "\033[m\033[1m", COLOR_LEN);
970 + } else if(strcmp(name, "none") == 0) {
971 + strncpy(dest, "\033[m", COLOR_LEN);
972 + } else {
973 + ret = 1;
975 + dest[COLOR_LEN] = '\0';
976 + return(ret);
979 +void _insert_color(FILE* stream, color_t color)
981 + switch(color) {
982 + case COLOR_RED:
983 + fprintf(stream, colortab.red);
984 + break;
985 + case COLOR_GREEN:
986 + fprintf(stream, colortab.green);
987 + break;
988 + case COLOR_YELLOW:
989 + fprintf(stream, colortab.yellow);
990 + break;
991 + case COLOR_BLUE:
992 + fprintf(stream, colortab.blue);
993 + break;
994 + case COLOR_MAGENTA:
995 + fprintf(stream, colortab.magenta);
996 + break;
997 + case COLOR_CYAN:
998 + fprintf(stream, colortab.cyan);
999 + break;
1000 + case COLOR_WHITE:
1001 + fprintf(stream, colortab.white);
1002 + break;
1003 + case COLOR_NONE:
1004 + fprintf(stream, colortab.none);
1005 + break;
1006 + default:;
1010 +int _parsecolorconfig(colortab_t* colortab, char* file)
1012 + _set_color_sequence("intensive red", colortab->red);
1013 + _set_color_sequence("intensive green", colortab->green);
1014 + _set_color_sequence("intensive yellow", colortab->yellow);
1015 + _set_color_sequence("intensive blue", colortab->blue);
1016 + _set_color_sequence("intensive magenta", colortab->magenta);
1017 + _set_color_sequence("intensive cyan", colortab->cyan);
1018 + _set_color_sequence("intensive foreground", colortab->white);
1019 + _set_color_sequence("none", colortab->none);
1021 + FILE* fp = NULL;
1022 + int linenum = 0;
1023 + char line[PATH_MAX+1];
1024 + char* ptr;
1026 + fp = fopen(file, "r");
1027 + if(fp == NULL) {
1028 + pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read.\n"), file);
1029 + return 1;
1031 + while(fgets(line, PATH_MAX, fp)) {
1032 + linenum++;
1033 + strtrim(line);
1035 + if(strlen(line) == 0 || line[0] == '#') {
1036 + continue;
1038 + if((ptr = strchr(line, '#'))) {
1039 + *ptr = '\0';
1042 + char* key = line;
1043 + ptr = line;
1044 + strsep(&ptr, "=");
1045 + strtrim(key);
1046 + strtrim(ptr);
1048 + if(key == NULL) {
1049 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: syntax error in config file- missing key.\n"),
1050 + file, linenum);
1051 + return 1;
1053 + if(strcmp(key, "Red") == 0) {
1054 + if(_set_color_sequence(ptr, colortab->red)) {
1055 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1056 + file, linenum, ptr);
1058 + } else if(strcmp(key, "Green") == 0) {
1059 + if(_set_color_sequence(ptr, colortab->green)) {
1060 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1061 + file, linenum, ptr);
1063 + } else if(strcmp(key, "Yellow") == 0) {
1064 + if(_set_color_sequence(ptr, colortab->yellow)) {
1065 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1066 + file, linenum, ptr);
1068 + } else if(strcmp(key, "Blue") == 0) {
1069 + if(_set_color_sequence(ptr, colortab->blue)) {
1070 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1071 + file, linenum, ptr);
1073 + } else if(strcmp(key, "Magenta") == 0) {
1074 + if(_set_color_sequence(ptr, colortab->magenta)) {
1075 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1076 + file, linenum, ptr);
1078 + } else if(strcmp(key, "Cyan") == 0) {
1079 + if(_set_color_sequence(ptr, colortab->cyan)) {
1080 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1081 + file, linenum, ptr);
1083 + } else if(strcmp(key, "White") == 0) {
1084 + if(_set_color_sequence(ptr, colortab->white)) {
1085 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: color '%s' not recognized.\n"),
1086 + file, linenum, ptr);
1088 + } else {
1089 + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"),
1090 + file, linenum, key);
1091 + return(1);
1094 + return(0);
1097 +int parsecolorconfig()
1099 + return(_parsecolorconfig(&colortab, "/etc/pacman.d/color.conf"));
1102 +int color_vfprintf(FILE* stream, const colordata_t* colors, const char* format, va_list args)
1104 + int ret = 0;
1106 + if(isatty(fileno(stream)) && colors) {
1107 + char* msg = NULL;
1108 + ret = vasprintf(&msg, format, args);
1109 + if(msg == NULL) {
1110 + return(ret);
1113 + const colordata_t* colorpos = colors;
1114 + color_t colorlast = COLOR_NONE;
1115 + int len = strlen(msg) + 1;
1116 + wchar_t* wcstr = calloc(len, sizeof(wchar_t));
1117 + len = mbstowcs(wcstr, msg, len);
1118 + free(msg);
1119 + const wchar_t *strpos = wcstr;
1121 + while(*strpos) {
1122 + if(colorpos->color != COLOR_END &&
1123 + ((colorpos->separator == SEP_ANY) ||
1124 + (colorpos->separator == SEP_LINE && *strpos == L'\n') ||
1125 + (colorpos->separator == SEP_COLON && (*strpos == L':' || *strpos == L':')))) {
1126 + _insert_color(stream, colorpos->color);
1127 + colorlast = colorpos->color;
1128 + colorpos++;
1130 + fprintf(stream, "%lc", (wint_t)*strpos);
1131 + strpos++;
1133 + free(wcstr);
1135 + if(colorlast != COLOR_NONE) {
1136 + _insert_color(stream, COLOR_NONE);
1138 + } else {
1139 + ret = vfprintf(stream, format, args);
1141 + return(ret);
1144 +int color_fprintf(FILE* stream, const colordata_t* colors, const char* format, ...)
1146 + int ret;
1147 + va_list args;
1148 + va_start(args, format);
1149 + ret = color_vfprintf(stream, colors, format, args);
1150 + va_end(args);
1151 + return(ret);
1154 +int color_printf(const colordata_t* colors, const char* format, ...)
1156 + int ret;
1157 + va_list args;
1158 + va_start(args, format);
1159 + ret = color_vfprintf(stdout, colors, format, args);
1160 + va_end(args);
1161 + return(ret);
1164 +void color_string_display(const colordata_t* colors_title, const char* title, const colordata_t* colors_string, const char* string)
1166 + if(title) {
1167 + color_printf(colors_title, "%s ", title);
1169 + if(string == NULL || string[0] == '\0') {
1170 + printf(_("None"));
1171 + } else {
1172 + color_printf(colors_string, "%s", string);
1174 + printf("\n");
1177 +const colordata_t COLOR_WHITE_ALL[] = {
1178 + { SEP_ANY, COLOR_WHITE },
1179 + { SEP_LINE, COLOR_NONE },
1180 + { SEP_ANY, COLOR_END } };
1182 +const colordata_t COLOR_GREEN_ALL[] = {
1183 + { SEP_ANY, COLOR_GREEN },
1184 + { SEP_LINE, COLOR_NONE },
1185 + { SEP_ANY, COLOR_END } };
1187 +const colordata_t COLOR_RED_ALL[] = {
1188 + { SEP_ANY, COLOR_RED },
1189 + { SEP_LINE, COLOR_NONE },
1190 + { SEP_ANY, COLOR_END } };
1192 +const colordata_t COLOR_BLUE_ALL[] = {
1193 + { SEP_ANY, COLOR_BLUE },
1194 + { SEP_LINE, COLOR_NONE },
1195 + { SEP_ANY, COLOR_END } };
1197 +const colordata_t COLOR_YELLOW_ALL[] = {
1198 + { SEP_ANY, COLOR_YELLOW },
1199 + { SEP_LINE, COLOR_NONE },
1200 + { SEP_ANY, COLOR_END } };
1202 +const colordata_t COLOR_MAGENTA_ALL[] = {
1203 + { SEP_ANY, COLOR_MAGENTA },
1204 + { SEP_LINE, COLOR_NONE },
1205 + { SEP_ANY, COLOR_END } };
1207 +const colordata_t COLOR_CYAN_ALL[] = {
1208 + { SEP_ANY, COLOR_CYAN },
1209 + { SEP_LINE, COLOR_NONE },
1210 + { SEP_ANY, COLOR_END } };
1212 +const colordata_t COLOR_DOUBLECOLON[] = {
1213 + { SEP_ANY, COLOR_BLUE },
1214 + { SEP_ANY, COLOR_SAME },
1215 + { SEP_ANY, COLOR_WHITE },
1216 + { SEP_LINE, COLOR_NONE },
1217 + { SEP_ANY, COLOR_END } };
1219 +const colordata_t COLOR_DOUBLECOLON2[] = {
1220 + { SEP_ANY, COLOR_BLUE },
1221 + { SEP_ANY, COLOR_SAME },
1222 + { SEP_ANY, COLOR_WHITE },
1223 + { SEP_LINE, COLOR_NONE },
1224 + { SEP_ANY, COLOR_BLUE },
1225 + { SEP_ANY, COLOR_SAME },
1226 + { SEP_ANY, COLOR_WHITE },
1227 + { SEP_LINE, COLOR_NONE },
1228 + { SEP_ANY, COLOR_END } };
1230 +const colordata_t COLOR_WHITE_COLON[] = {
1231 + { SEP_ANY, COLOR_WHITE },
1232 + { SEP_COLON, COLOR_SAME },
1233 + { SEP_ANY, COLOR_NONE },
1234 + { SEP_ANY, COLOR_END } };
1236 /* vim: set ts=2 sw=2 noet: */
1237 diff -Npaur a/src/pacman/util.h b/src/pacman/util.h
1238 --- a/src/pacman/util.h 2011-10-21 18:43:49.000000000 +0300
1239 +++ b/src/pacman/util.h 2011-11-22 00:34:58.250461929 +0200
1240 @@ -45,6 +45,48 @@ typedef struct _pm_target_t {
1241 int is_explicit;
1242 } pm_target_t;
1244 +/* pacman-color */
1245 +typedef enum _separator_t {
1246 + SEP_ANY = 0,
1247 + SEP_LINE,
1248 + SEP_COLON,
1249 +} separator_t;
1251 +typedef enum _color_t {
1252 + COLOR_END = 0,
1253 + COLOR_SAME,
1254 + COLOR_RED,
1255 + COLOR_GREEN,
1256 + COLOR_YELLOW,
1257 + COLOR_BLUE,
1258 + COLOR_MAGENTA,
1259 + COLOR_CYAN,
1260 + COLOR_WHITE,
1261 + COLOR_NONE,
1262 +} color_t;
1264 +typedef struct _colordata_t {
1265 + separator_t separator;
1266 + color_t color;
1267 +} colordata_t;
1269 +extern const colordata_t COLOR_WHITE_ALL[];
1270 +extern const colordata_t COLOR_GREEN_ALL[];
1271 +extern const colordata_t COLOR_RED_ALL[];
1272 +extern const colordata_t COLOR_BLUE_ALL[];
1273 +extern const colordata_t COLOR_YELLOW_ALL[];
1274 +extern const colordata_t COLOR_MAGENTA_ALL[];
1275 +extern const colordata_t COLOR_CYAN_ALL[];
1276 +extern const colordata_t COLOR_DOUBLECOLON[];
1277 +extern const colordata_t COLOR_DOUBLECOLON2[];
1278 +extern const colordata_t COLOR_WHITE_COLON[];
1280 +int parsecolorconfig();
1281 +int color_fprintf(FILE* stream, const colordata_t* colors, const char* format, ...) __attribute__((format(printf,3,4)));
1282 +int color_printf(const colordata_t* colors, const char* format, ...) __attribute__((format(printf,2,3)));
1283 +int color_vfprintf(FILE* stream, const colordata_t* colors, const char* format, va_list args) __attribute__((format(printf,3,0)));
1284 +void color_string_display(const colordata_t* colors_title, const char* title, const colordata_t* colors_string, const char* string);
1286 void trans_init_error(void);
1287 int trans_init(alpm_transflag_t flags, int check_valid);
1288 int trans_release(void);
1289 @@ -59,11 +101,11 @@ char *strtoupper(char *str);
1290 char *strtrim(char *str);
1291 char *strreplace(const char *str, const char *needle, const char *replace);
1292 alpm_list_t *strsplit(const char *str, const char splitchar);
1293 -void string_display(const char *title, const char *string);
1294 +void string_display(const colordata_t *colors_title, const char *title, const char *string);
1295 double humanize_size(off_t bytes, const char target_unit, const char **label);
1296 int table_display(const char *title, const alpm_list_t *header, const alpm_list_t *rows);
1297 -void list_display(const char *title, const alpm_list_t *list);
1298 -void list_display_linebreak(const char *title, const alpm_list_t *list);
1299 +void list_display(const colordata_t *colors_title, const char *title, const alpm_list_t *list);
1300 +void list_display_linebreak(const colordata_t *colors_title, const char *title, const alpm_list_t *list);
1301 void signature_display(const char *title, alpm_siglist_t *siglist);
1302 void display_targets(void);
1303 int str_cmp(const void *s1, const void *s2);
1304 @@ -73,8 +115,8 @@ void print_packages(const alpm_list_t *p
1305 void select_display(const alpm_list_t *pkglist);
1306 int select_question(int count);
1307 int multiselect_question(char *array, int count);
1308 -int yesno(char *fmt, ...);
1309 -int noyes(char *fmt, ...);
1310 +int yesno(const colordata_t *colors, char *fmt, ...);
1311 +int noyes(const colordata_t *colors, char *fmt, ...);
1313 int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
1314 int pm_asprintf(char **string, const char *format, ...);