pager: don't start pager if the terminal is explicitly set to TERM=dumb

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.
This commit is contained in:
Lennart Poettering
2016-05-30 18:23:54 +02:00
parent 7565bb98a4
commit ac96418b4f
4 changed files with 17 additions and 5 deletions
+14 -3
View 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;
+1
View 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) {
+1 -1
View 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));
+1 -1
View 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");