Disable colored output when not running in TTY
Closed this issue · 0 comments
der-eismann commented
I think we had this issue with legacy-moss already, that when you pipe the output you have all these escape chars in your text:
The following package(s) will be installed:
�[1macl�[0m �[38;5;13m2.3.1�[39m-�[2m2�[0m �[1mdbus�[0m �[38;5;13m1.14.6�[39m-�[2m3�[0m �[1mgzip�[0m �[38;5;13m1.12�[39m-�[2m3�[0m �[1mlld�[0m �[38;5;13m16.0.4�[39m-�[2m8�[0m �[1mperl�[0m �[38;5;13m5.36.0�[39m-�[2m4�[0m
�[1mattr�[0m �[38;5;13m2.5.1�[39m-�[2m2�[0m �[1mdiffutils�[0m �[38;5;13m3.10�[39m-�[2m4�[0m �[1mkmod�[0m �[38;5;13m30�[39m-�[2m5�[0m �[1mllvm�[0m �[38;5;13m16.0.4�[39m-�[2m8�[0m �[1mpkgconf�[0m �[38;5;13m1.9.5�[39m-�[2m7�[0m
�[1mautoconf�[0m �[38;5;13m2.72�[39m-�[2m4�[0m �[1mexpat�[0m �[38;5;13m2.5.0�[39m-�[2m3�[0m �[1mlibarchive�[0m �[38;5;13m3.6.2�[39m-�[2m2�[0m �[1mllvm-libs�[0m �[38;5;13m16.0.4�[39m-�[2m8�[0m �[1mpython�[0m �[38;5;13m3.11.2�[39m-�[2m3�[0m
�[1mautomake�[0m �[38;5;13m1.16.5�[39m-�[2m3�[0m �[1mfakeroot�[0m �[38;5;13m1.31�[39m-�[2m2�[0m �[1mlibcap�[0m �[38;5;13m2.68�[39m-�[2m4�[0m �[1mlz4�[0m �[38;5;13m1.9.4�[39m-�[2m1�[0m �[1mreadline�[0m �[38;5;13m8.2�[39m-�[2m3�[0m
�[1mbash�[0m �[38;5;13m5.2.15�[39m-�[2m5�[0m �[1mfindutils�[0m �[38;5;13m4.9.0�[39m-�[2m2�[0m �[1mlibcap-ng�[0m �[38;5;13m0.8.3�[39m-�[2m2�[0m �[1mm4�[0m �[38;5;13m1.4.19�[39m-�[2m2�[0m �[1msed�[0m �[38;5;13m4.9�[39m-�[2m2�[0m
�[1mboulder�[0m �[38;5;13m1.0.1�[39m-�[2m38�[0m �[1mgawk�[0m �[38;5;13m5.2.2�[39m-�[2m3�[0m �[1mlibcxx�[0m �[38;5;13m16.0.4�[39m-�[2m7�[0m �[1mmake�[0m �[38;5;13m4.4.1�[39m-�[2m3�[0m �[1mslibtool�[0m �[38;5;13m0.5.34�[39m-�[2m4�[0m
�[1mbrotli�[0m �[38;5;13m1.0.9�[39m-�[2m3�[0m �[1mgdbm�[0m �[38;5;13m1.23�[39m-�[2m2�[0m �[1mlibcxx-devel�[0m �[38;5;13m16.0.4�[39m-�[2m7�[0m �[1mmoss-container�[0m �[38;5;13m0.2�[39m-�[2m5�[0m �[1msystemd�[0m �[38;5;13m252.7�[39m-�[2m9�[0m
�[1mbzip2�[0m �[38;5;13m1.0.8�[39m-�[2m2�[0m �[1mgettext�[0m �[38;5;13m0.21.1�[39m-�[2m3�[0m �[1mlibffi�[0m �[38;5;13m3.4.4�[39m-�[2m3�[0m �[1mmpfr�[0m �[38;5;13m4.2.0�[39m-�[2m3�[0m �[1mutil-linux�[0m �[38;5;13m2.39.3�[39m-�[2m6�[0m
�[1mclang�[0m �[38;5;13m16.0.4�[39m-�[2m8�[0m �[1mgettext-devel�[0m �[38;5;13m0.21.1�[39m-�[2m3�[0m �[1mlibunistring�[0m �[38;5;13m1.1�[39m-�[2m1�[0m �[1mncurses�[0m �[38;5;13m6.4�[39m-�[2m8�[0m �[1mxxhash�[0m �[38;5;13m0.8.1�[39m-�[2m5�[0m
�[1mclang-libs�[0m �[38;5;13m16.0.4�[39m-�[2m8�[0m �[1mglibc�[0m �[38;5;13m2.37�[39m-�[2m6�[0m �[1mlibxcrypt�[0m �[38;5;13m4.4.35�[39m-�[2m4�[0m �[1mnghttp2�[0m �[38;5;13m1.52.0�[39m-�[2m3�[0m �[1mxz�[0m �[38;5;13m5.4.5�[39m-�[2m8�[0m
�[1mcoreutils�[0m �[38;5;13m9.3�[39m-�[2m4�[0m �[1mglibc-devel�[0m �[38;5;13m2.37�[39m-�[2m6�[0m �[1mlibxml2�[0m �[38;5;13m2.10.4�[39m-�[2m5�[0m �[1mnss�[0m �[38;5;13m3.94�[39m-�[2m9�[0m �[1mzlib�[0m �[38;5;13m1.3�[39m-�[2m9�[0m
�[1mcurl�[0m �[38;5;13m8.5.0�[39m-�[2m8�[0m �[1mgmp�[0m �[38;5;13m6.2.1�[39m-�[2m2�[0m �[1mlinux-headers�[0m �[38;5;13m6.4.0�[39m-�[2m13�[0m �[1mopenssl�[0m �[38;5;13m3.1.3�[39m-�[2m7�[0m �[1mzstd�[0m �[38;5;13m1.5.5�[39m-�[2m4�[0m
�[1mdash�[0m �[38;5;13m0.5.12�[39m-�[2m2�[0m �[1mgrep�[0m �[38;5;13m3.11�[39m-�[2m5�[0m �[1mlinux-pam�[0m �[38;5;13m1.5.2�[39m-�[2m6�[0m �[1mpcre2�[0m �[38;5;13m10.42�[39m-�[2m3�[0m
moss and all other CLI tools should be able to detect a TTY and if there is none, disable color. Ideally all the progress lines can be logged as well, e.g.
Indexed yq-4.40.5-3-1-x86_64.stone
Indexed util-linux-2.39.3-6-1-x86_64.stone
Indexed vim-9.1.0031-5-1-x86_64.stone
Indexed git-dbginfo-2.43.0-7-1-x86_64.stone
- | 54%| Hashing git-2.43.0-7-1-x86_64.stone 10.40 MiB/s
- | 92%| Hashing moss-dbginfo-0.1.0-19-1-x86_64.stone
These just completely disappear when redirecting stdout to a file.