summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fdisks/fdisk.c4
-rw-r--r--include/colors.h5
-rw-r--r--include/pathnames.h3
-rw-r--r--lib/colors.c29
-rw-r--r--misc-utils/cal.c4
-rw-r--r--sys-utils/dmesg.c4
-rw-r--r--text-utils/hexdump.c4
7 files changed, 39 insertions, 14 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 7afd6420b..a5c1fe634 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -397,7 +397,7 @@ enum {
int main(int argc, char **argv)
{
int i, c, act = ACT_FDISK;
- int colormode = UL_COLORMODE_AUTO;
+ int colormode = UL_COLORMODE_UNDEF;
struct fdisk_context *cxt;
setlocale(LC_ALL, "");
@@ -500,7 +500,7 @@ int main(int argc, char **argv)
warnx(_("The device properties (sector size and geometry) should"
" be used with one specified device only."));
- colors_init(colormode);
+ colors_init(colormode, "fdisk");
switch (act) {
case ACT_LIST:
diff --git a/include/colors.h b/include/colors.h
index 16db01075..42881d5e3 100644
--- a/include/colors.h
+++ b/include/colors.h
@@ -43,6 +43,7 @@ enum colortmode {
UL_COLORMODE_AUTO = 0,
UL_COLORMODE_NEVER,
UL_COLORMODE_ALWAYS,
+ UL_COLORMODE_UNDEF,
__UL_NCOLORMODES /* last */
};
@@ -50,8 +51,8 @@ enum colortmode {
extern int colormode_from_string(const char *str);
extern int colormode_or_err(const char *str, const char *errmsg);
-/* Initialize the global variable OUT_IS_TERM */
-extern int colors_init(int mode);
+/* Initialize the global variable UL_COLOR_TERM_OK */
+extern int colors_init(int mode, const char *util_name);
/* Returns 1 or 0 */
extern int colors_wanted(void);
diff --git a/include/pathnames.h b/include/pathnames.h
index 2957dacb5..94cc412a7 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -50,6 +50,9 @@
#define _PATH_SECURE "/etc/securesingle"
#define _PATH_USERTTY "/etc/usertty"
+#define _PATH_TERMCOLORS_DIR "/etc/terminal-colors.d/"
+#define _PATH_TERMCOLORS_DISABLE _PATH_TERMCOLORS_DIR "disable"
+
/* used in login-utils/shutdown.c */
/* used in login-utils/setpwnam.h and login-utils/islocal.c */
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;
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 747694d75..81375fe19 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -266,7 +266,7 @@ int main(int argc, char **argv)
static struct cal_control ctl = {
.weekstart = SUNDAY,
.num_months = NUM_MONTHS,
- .colormode = UL_COLORMODE_AUTO,
+ .colormode = UL_COLORMODE_UNDEF,
.weektype = WEEK_NUM_DISABLED,
.day_width = DAY_LEN,
.gutter_width = 2,
@@ -469,7 +469,7 @@ int main(int argc, char **argv)
headers_init(&ctl);
- if (!colors_init(ctl.colormode)) {
+ if (!colors_init(ctl.colormode, "cal")) {
ctl.req.day = 0;
ctl.weektype &= ~WEEK_NUM_MASK;
}
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 3ed0b1db7..c1f84a568 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -1187,7 +1187,7 @@ int main(int argc, char *argv[])
.kmsg = -1,
.time_fmt = DMESG_TIMEFTM_TIME,
};
- int colormode = UL_COLORMODE_NEVER;
+ int colormode = UL_COLORMODE_UNDEF;
enum {
OPT_TIME_FORMAT = CHAR_MAX + 1,
};
@@ -1377,7 +1377,7 @@ int main(int argc, char *argv[])
}
- ctl.color = colors_init(colormode) ? 1 : 0;
+ ctl.color = colors_init(colormode, "dmesg") ? 1 : 0;
if (ctl.follow)
nopager = 1;
ctl.pager = nopager ? 0 : ctl.pager;
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 19e67f46d..ec9fecbec 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -60,7 +60,7 @@ int
parse_args(int argc, char **argv, struct hexdump *hex)
{
int ch;
- int colormode = UL_COLORMODE_NEVER;
+ int colormode = UL_COLORMODE_UNDEF;
char *hex_offt = "\"%07.7_Ax\n\"";
@@ -145,7 +145,7 @@ parse_args(int argc, char **argv, struct hexdump *hex)
add_fmt(hex_offt, hex);
add_fmt("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"", hex);
}
- colors_init (colormode);
+ colors_init (colormode, "hexdump");
return optind;
}