Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-05-23 15:14:10 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-04 23:39:10 +0300
commit3d9c64915810cf684d75c8697b42e30c14011324 (patch)
tree96724f31a704818382107050a1ab9fe1dfbf25d9 /libbb/xfuncs.c
parent5a3d3b8055f684539f05e00c38fdc5cefb94c883 (diff)
ls: don't output any colors with TERM=dumb
The TERM variable is usually set to "dumb" to indicate that the terminal does not support any ANSI escape sequences. Presently, ls does not honor this variable and outputs colors anyhow which results in unreadable output, unless the user explicitly disables colors using `ls --color=never`. The rational behind this change is that ls should "just work" by default, even on dumb terminals. For this reason, this patch adds a check which additionally consults the TERM variable before printing any colors. This is analogous to the existing check for ensuring that standard output is a tty. As such, colors can still be forced with `--color=force`, even if TERM is set to dumb. function old new delta is_TERM_dumb - 40 +40 ls_main 579 598 +19 .rodata 103246 103251 +5 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 64/0) Total: 64 bytes Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index d93d8aaf5..c81ce4546 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -303,6 +303,12 @@ int FAST_FUNC get_terminal_width(int fd)
return width;
}
+int FAST_FUNC is_dumb_term(void)
+{
+ char *term = getenv("TERM");
+ return term && strcmp(term, "dumb") == 0;
+}
+
int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp)
{
return tcsetattr(STDIN_FILENO, TCSANOW, tp);