diff options
author | Karel Zak | 2014-03-11 10:38:15 +0100 |
---|---|---|
committer | Karel Zak | 2014-03-11 10:38:15 +0100 |
commit | 329b0ee753f29fab348a189749e1d2f268e90286 (patch) | |
tree | 00af9e349ed669a8d9b6b1f1683e6c160a370063 /lib/colors.c | |
parent | lib/colors: add info to man pages, add terminal-colors.d.5 (diff) | |
download | kernel-qcow2-util-linux-329b0ee753f29fab348a189749e1d2f268e90286.tar.gz kernel-qcow2-util-linux-329b0ee753f29fab348a189749e1d2f268e90286.tar.xz kernel-qcow2-util-linux-329b0ee753f29fab348a189749e1d2f268e90286.zip |
lib/colors: support <name>.enable too
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/colors.c')
-rw-r--r-- | lib/colors.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/colors.c b/lib/colors.c index bf5fa855d..15123168d 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -16,23 +16,27 @@ static int ul_color_term_ok; 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]; + if (mode == UL_COLORMODE_UNDEF) { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s%s%s", + _PATH_TERMCOLORS_DIR, name, ".enable"); + + if (access(path, F_OK) == 0) + mode = UL_COLORMODE_AUTO; + else { snprintf(path, sizeof(path), "%s%s%s", _PATH_TERMCOLORS_DIR, name, ".disable"); - if (access(path, F_OK) == 0) { - ul_color_term_ok = 0; - break; - } + if (access(_PATH_TERMCOLORS_DISABLE, F_OK) == 0 || + access(path, F_OK) == 0) + mode = UL_COLORMODE_NEVER; + else + mode = UL_COLORMODE_AUTO; } - /* fallthrough */ + } + + switch (mode) { case UL_COLORMODE_AUTO: ul_color_term_ok = isatty(STDOUT_FILENO); break; |