]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pager: don't start pager if the terminal is explicitly set to TERM=dumb
authorLennart Poettering <lennart@poettering.net>
Mon, 30 May 2016 16:23:54 +0000 (18:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 30 May 2016 16:23:54 +0000 (18:23 +0200)
As suggested here:

https://bugs.freedesktop.org/show_bug.cgi?id=64737#c8

This adds a new call terminal_is_dumb() and makes use of this where
appropriate.

src/basic/terminal-util.c
src/basic/terminal-util.h
src/cgtop/cgtop.c
src/shared/pager.c

index 2b90f2e5a1e9060fc77c98961fe3038b720d7ecc..d8cca55378ec89339d868a446e59da42869b8ad4 100644 (file)
@@ -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;
index b4493709749f3d7425353ed98f8cb621498f6447..169ab772ffd97141398f354158a9b8f578cb5bad 100644 (file)
@@ -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) {
index e088e4b197de4b91629da980b01a444483f5f272..33379eb9bd02ad09116528bd35b963045e5d2de3 100644 (file)
@@ -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));
index c16bc027be682f47d9872bf85ab59c28194aa59d..a2524d44205dd26adffd4017856cf15d53df0da5 100644 (file)
@@ -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");