summaryrefslogtreecommitdiffstats
path: root/lib/colors.c
diff options
context:
space:
mode:
authorOndrej Oprala2014-01-23 13:03:45 +0100
committerKarel Zak2014-03-11 09:38:09 +0100
commitd0c9ddc3cc18f0f374a0d13516dacbda2e3a1a0c (patch)
treee3022408c0a770a666be7ff829e3f9291883cf59 /lib/colors.c
parenttests: check commands needed for running a test exist (diff)
downloadkernel-qcow2-util-linux-d0c9ddc3cc18f0f374a0d13516dacbda2e3a1a0c.tar.gz
kernel-qcow2-util-linux-d0c9ddc3cc18f0f374a0d13516dacbda2e3a1a0c.tar.xz
kernel-qcow2-util-linux-d0c9ddc3cc18f0f374a0d13516dacbda2e3a1a0c.zip
lib/colors: check for /etc/terminal-colors.d/[util].disable
[kzak@redhat.com: - move paths to pathnames.h, - use static path buffer] Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/colors.c')
-rw-r--r--lib/colors.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/colors.c b/lib/colors.c
index a197823b4..bf5fa855d 100644
--- a/lib/colors.c
+++ b/lib/colors.c
@@ -6,14 +6,33 @@
*/
#include <c.h>
#include <assert.h>
+#include <sys/stat.h>
#include "colors.h"
+#include "xalloc.h"
+#include "pathnames.h"
static int ul_color_term_ok;
-int colors_init(int mode)
+int colors_init(int mode, const char *name)
{
switch (mode) {
+ case UL_COLORMODE_UNDEF:
+ if (access(_PATH_TERMCOLORS_DISABLE, F_OK) == 0) {
+ ul_color_term_ok = 0;
+ break;
+ } else {
+ char path[PATH_MAX];
+
+ snprintf(path, sizeof(path), "%s%s%s",
+ _PATH_TERMCOLORS_DIR, name, ".disable");
+
+ if (access(path, F_OK) == 0) {
+ ul_color_term_ok = 0;
+ break;
+ }
+ }
+ /* fallthrough */
case UL_COLORMODE_AUTO:
ul_color_term_ok = isatty(STDOUT_FILENO);
break;
@@ -50,7 +69,8 @@ int colormode_from_string(const char *str)
static const char *modes[] = {
[UL_COLORMODE_AUTO] = "auto",
[UL_COLORMODE_NEVER] = "never",
- [UL_COLORMODE_ALWAYS] = "always"
+ [UL_COLORMODE_ALWAYS] = "always",
+ [UL_COLORMODE_UNDEF] = ""
};
if (!str || !*str)
@@ -144,8 +164,9 @@ int main(int argc, char *argv[])
}
}
- colors_init(mode);
- color_enable(colorscheme_from_string(scheme));
+ colors_init(mode, program_invocation_short_name);
+ color_enable(UL_COLOR_RED);
+
printf("Hello World!");
color_disable();
return EXIT_SUCCESS;