summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/terminal-util.c17
-rw-r--r--src/basic/terminal-util.h1
-rw-r--r--src/cgtop/cgtop.c2
-rw-r--r--src/shared/pager.c2
4 files changed, 17 insertions, 5 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 2b90f2e5a1..d8cca55378 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -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) {
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index e088e4b197..33379eb9bd 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -558,7 +558,7 @@ static void display(Hashmap *a) {
assert(a);
- if (on_tty())
+ if (!terminal_is_dumb())
fputs(ANSI_HOME_CLEAR, stdout);
array = alloca(sizeof(Group*) * hashmap_size(a));
diff --git a/src/shared/pager.c b/src/shared/pager.c
index c16bc027be..a2524d4420 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -63,7 +63,7 @@ int pager_open(bool no_pager, bool jump_to_end) {
if (pager_pid > 0)
return 1;
- if (!on_tty())
+ if (terminal_is_dumb())
return 0;
pager = getenv("SYSTEMD_PAGER");