summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-06-04 18:47:56 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-06-04 18:47:56 -0400
commit20f8477be541f2486737f1be32bdb0bd0d6372fd (patch)
treeb99412abf9bf45fddc04ef330f5546059d3a444d /src/basic
parent3fb1ac5d57954bb0d881a68777e996b46ed44ce3 (diff)
parentac83514cbf5997938344d5fbcfcbfd5021f453f9 (diff)
Merge pull request #3392 from poettering/assorted-stuff
Assorted stuff
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/string-util.h4
-rw-r--r--src/basic/terminal-util.c25
-rw-r--r--src/basic/terminal-util.h1
3 files changed, 23 insertions, 7 deletions
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index 139cc8c91b..1209e1e2e1 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -66,6 +66,10 @@ static inline bool isempty(const char *p) {
return !p || !p[0];
}
+static inline const char *empty_to_null(const char *p) {
+ return isempty(p) ? NULL : p;
+}
+
static inline char *startswith(const char *s, const char *prefix) {
size_t l;
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 3189b8789d..d8cca55378 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -155,14 +155,14 @@ int ask_char(char *ret, const char *replies, const char *text, ...) {
char c;
bool need_nl = true;
- if (on_tty())
+ if (colors_enabled())
fputs(ANSI_HIGHLIGHT, stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
- if (on_tty())
+ if (colors_enabled())
fputs(ANSI_NORMAL, stdout);
fflush(stdout);
@@ -199,14 +199,14 @@ int ask_string(char **ret, const char *text, ...) {
char line[LINE_MAX];
va_list ap;
- if (on_tty())
+ if (colors_enabled())
fputs(ANSI_HIGHLIGHT, stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
- if (on_tty())
+ if (colors_enabled())
fputs(ANSI_NORMAL, stdout);
fflush(stdout);
@@ -1193,6 +1193,19 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
return receive_one_fd(pair[0], 0);
}
+bool terminal_is_dumb(void) {
+ const char *e;
+
+ if (!on_tty())
+ return true;
+
+ e = getenv("TERM");
+ if (!e)
+ return true;
+
+ return streq(e, "dumb");
+}
+
bool colors_enabled(void) {
static int enabled = -1;
@@ -1202,10 +1215,8 @@ bool colors_enabled(void) {
colors = getenv("SYSTEMD_COLORS");
if (colors)
enabled = parse_boolean(colors) != 0;
- else if (streq_ptr(getenv("TERM"), "dumb"))
- enabled = false;
else
- enabled = on_tty();
+ enabled = !terminal_is_dumb();
}
return enabled;
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
index b449370974..169ab772ff 100644
--- a/src/basic/terminal-util.h
+++ b/src/basic/terminal-util.h
@@ -80,6 +80,7 @@ unsigned lines(void);
void columns_lines_cache_reset(int _unused_ signum);
bool on_tty(void);
+bool terminal_is_dumb(void);
bool colors_enabled(void);
static inline const char *ansi_underline(void) {