From 1febd85f420cdd617b18c3d4d62fcc9573ea5d7f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 15 Oct 2009 16:17:31 +0200 Subject: [PATCH] xbps-pkgdb, shutils: use red/bold, red/yellow and bold for msg_error, msg_warn and msg_normal respectively. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091015141731-9ci2bnvslqe5gq7j --- bin/xbps-pkgdb/main.c | 41 +++++++++++++++++++++++++++-------------- shutils/common_funcs.sh | 11 ++++++++++- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index 18ccefa2..a841cc05 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -31,6 +31,14 @@ #include +/* error messages in bold/red */ +#define MSG_ERROR "\033[1m\033[31m" +/* warn messages in bold/yellow */ +#define MSG_WARN "\033[1m\033[33m" +/* normal messages in bold */ +#define MSG_NORMAL "\033[1m" +#define MSG_RESET "\033[m" + static void write_plist_file(prop_dictionary_t dict, const char *file) { @@ -109,8 +117,8 @@ main(int argc, char **argv) plist = xbps_xasprintf("%s/%s/%s", root, XBPS_META_PATH, XBPS_REGPKGDB); if (plist == NULL) { - printf("=> ERROR: couldn't find regpkdb file (%s)\n", - strerror(errno)); + printf("%s=> ERROR: couldn't find regpkdb file (%s)%s\n", + MSG_ERROR, strerror(errno), MSG_RESET); exit(EXIT_FAILURE); } @@ -137,15 +145,18 @@ main(int argc, char **argv) rv = xbps_register_pkg(dict, false); if (rv == EEXIST) { - printf("%s=> %s-%s already registered.\n", - in_chroot ? "[chroot] " : "", argv[1], argv[2]); + printf("%s%s=> %s-%s already registered.%s\n", MSG_WARN, + in_chroot ? "[chroot] " : "", argv[1], argv[2], + MSG_RESET); } else if (rv != 0) { - printf("%s=> couldn't register %s-%s (%s).\n", + printf("%s%s=> couldn't register %s-%s " + "(%s).%s\n", MSG_ERROR, in_chroot ? "[chroot] " : "" , argv[1], argv[2], - strerror(rv)); + strerror(rv), MSG_RESET); } else { - printf("%s=> %s-%s registered successfully.\n", - in_chroot ? "[chroot] " : "", argv[1], argv[2]); + printf("%s%s=> %s-%s registered successfully.%s\n", + MSG_NORMAL, in_chroot ? "[chroot] " : "", + argv[1], argv[2], MSG_RESET); } } else if (strcasecmp(argv[0], "unregister") == 0) { @@ -155,16 +166,18 @@ main(int argc, char **argv) rv = xbps_remove_pkg_dict_from_file(argv[1], plist); if (rv == ENOENT) { - printf("=> ERROR: %s not registered in database.\n", - argv[1]); + printf("%s=> ERROR: %s not registered " + "in database.%s\n", MSG_WARN, argv[1], MSG_RESET); } else if (rv != 0) { - printf("=> ERROR: couldn't unregister %s " - "from database (%s)\n", argv[1], strerror(rv)); + printf("%s=> ERROR: couldn't unregister %s " + "from database (%s)%s\n", MSG_ERROR, + argv[1], strerror(rv), MSG_RESET); exit(EXIT_FAILURE); } - printf("%s=> %s-%s unregistered successfully.\n", - in_chroot ? "[chroot] " : "", argv[1], argv[2]); + printf("%s%s=> %s-%s unregistered successfully.%s\n", + MSG_NORMAL, in_chroot ? "[chroot] " : "", argv[1], + argv[2], MSG_RESET); } else if (strcasecmp(argv[0], "version") == 0) { /* Prints version of an installed package */ diff --git a/shutils/common_funcs.sh b/shutils/common_funcs.sh index 42ab197a..fc0c40fd 100644 --- a/shutils/common_funcs.sh +++ b/shutils/common_funcs.sh @@ -1,5 +1,5 @@ #- -# Copyright (c) 2008 Juan Romero Pardines. +# Copyright (c) 2008-2009 Juan Romero Pardines. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -61,11 +61,14 @@ msg_error() { [ -z "$1" ] && return 1 + # error messages in bold/red + printf "\033[1m\033[31m" if [ -n "$in_chroot" ]; then echo "[chroot] => ERROR: $1" else echo "=> ERROR: $1" fi + printf "\033[m" exit 1 } @@ -74,20 +77,26 @@ msg_warn() { [ -z "$1" ] && return 1 + # warn messages in bold/yellow + printf "\033[1m\033[33m" if [ -n "$in_chroot" ]; then echo "[chroot] => WARNING: $1" else echo "=> WARNING: $1" fi + printf "\033[m" } msg_normal() { [ -z "$1" ] && return 1 + # normal messages in bold + printf "\033[1m" if [ -n "$in_chroot" ]; then echo "[chroot] => $1" else echo "=> $1" fi + printf "\033[m" }