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, "");
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:
UL_COLORMODE_AUTO = 0,
UL_COLORMODE_NEVER,
UL_COLORMODE_ALWAYS,
+ UL_COLORMODE_UNDEF,
__UL_NCOLORMODES /* last */
};
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);
#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 */
*/
#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;
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)
}
}
- 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;
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,
headers_init(&ctl);
- if (!colors_init(ctl.colormode)) {
+ if (!colors_init(ctl.colormode, "cal")) {
ctl.req.day = 0;
ctl.weektype &= ~WEEK_NUM_MASK;
}
.kmsg = -1,
.time_fmt = DMESG_TIMEFTM_TIME,
};
- int colormode = UL_COLORMODE_NEVER;
+ int colormode = UL_COLORMODE_UNDEF;
enum {
OPT_TIME_FORMAT = CHAR_MAX + 1,
};
}
- 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;
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\"";
add_fmt(hex_offt, hex);
add_fmt("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"", hex);
}
- colors_init (colormode);
+ colors_init (colormode, "hexdump");
return optind;
}