Bug 64737

Summary: RFE: add option to optionally turn of color output in systemd tools
Product: systemd Reporter: Jonathan Liu <net147>
Component: generalAssignee: systemd-bugs
Status: RESOLVED FIXED QA Contact: systemd-bugs
Severity: normal    
Priority: medium CC: jari.aalto
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Jonathan Liu 2013-05-18 11:05:53 UTC
systemctl can't always assume the PAGER supports handling and passthrough of ANSI escape sequences (e.g. for color and bold). For example, busybox less treats ESC as an unprintable character and escapes it.
Comment 1 Zbigniew Jedrzejewski-Szmek 2013-06-03 18:24:54 UTC
Hi,

we set the less options to LESS=FRSXMK. Special less'es which don't support those options are not something that is very common, so fixing this is definitely not high priority. In general systems supports color-less output, and extending this to systemctl shouldn't be too hard, it should be enough to add --no-color option, defaulting to !on_tty(), and use this new variable to determine whether color is enabled. We'd be happy to apply a patch, but at least I'm not going to work on this.
Comment 2 Zbigniew Jedrzejewski-Szmek 2013-06-10 15:02:19 UTC
http://cgit.freedesktop.org/systemd/systemd/commit/?id=3001c745 is related.
Comment 3 Zbigniew Jedrzejewski-Szmek 2015-01-12 05:26:43 UTC
http://man7.org/linux/man-pages/man5/terminal-colors.d.5.html is probably the way to do this.
Comment 4 Lennart Poettering 2015-01-28 20:47:00 UTC
terminal-colors.d/ really appears a bit over-the-top. I am really not convinced that that would be a good idea.

We can add $SYSTEMD_COLOR=0 or so, but that's really all...
Comment 5 Lennart Poettering 2015-05-15 14:14:09 UTC
*** Bug 90464 has been marked as a duplicate of this bug. ***
Comment 6 cbeytas 2015-09-06 15:58:10 UTC
There are thousands of embedded systems out there that use busybox and are now transitioning to systemd. The output from systemctl is nearly unreadable.
The busybox 'less' command doesn't support the -R switch.

Please, do things properly. Colors should be always be opt-in.
If everyone did things the right way then we wouldn't have all these problems.

For reference:
https://bugs.busybox.net/show_bug.cgi?id=5546
Comment 7 Lennart Poettering 2016-02-01 17:59:50 UTC
This exists in systemd git now. Simply set the SYSTEMD_COLORS=0 env var.
Comment 8 Rob Nagler 2016-05-26 16:12:52 UTC
Thank you for fixing this, but I do have a problem with the solution.

Today, I finally got fed up with systemctl saying "WARNING: terminal is not fully functional" even though I already know that, having set $TERM to "dumb" in my rc file. One could argue that error is the fault of less, but systemctl/etc. also should respect $TERM, And, while it is handling the case of no color, it shouldn't call less unless $PAGER or $SYSTEMD_PAGER is set explicitly.

It is unreasonable for users to have to discover and to configure Yet Another Environment Variable[1] when $TERM is set correctly to dumb, which has been a de facto standard on Unix since 1978.

In my particular case, I use Emacs shells (not terminals) for system interactions. There are, of course, plenty of other reasons programs should respect $TERM. The primary one being: It's correct. :)

[1] http://www.joelonsoftware.com/uibook/chapters/fog0000000059.html
Comment 9 Lennart Poettering 2016-05-27 16:49:22 UTC
systemd doesn't print "WARNING: terminal is not fully functional". Maybe your pager does that? less?
Comment 10 Lennart Poettering 2016-05-27 16:50:18 UTC
But yeah, it might make sense to skip invoking a pager if TERM is not set or set to "dumb".
Comment 11 Lennart Poettering 2016-06-06 10:17:57 UTC
The TERM=dumb check has been added now.

https://github.com/systemd/systemd/pull/3392

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.