serpent-os / moss

The safe, fast and sane package manager for Linux
https://serpentos.com
71 stars 9 forks source link

Disable colored output when not running in TTY #122

Closed der-eismann closed 4 months ago

der-eismann commented 5 months ago

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:
acl                  2.3.1-2   dbus                1.14.6-3   gzip                  1.12-3   lld                 16.0.4-8   perl                5.36.0-4
attr                 2.5.1-2   diffutils             3.10-4   kmod                    30-5   llvm                16.0.4-8   pkgconf              1.9.5-7
autoconf              2.72-4   expat                2.5.0-3   libarchive           3.6.2-2   llvm-libs           16.0.4-8   python              3.11.2-3
automake            1.16.5-3   fakeroot              1.31-2   libcap                2.68-4   lz4                  1.9.4-1   readline               8.2-3
bash                5.2.15-5   findutils            4.9.0-2   libcap-ng            0.8.3-2   m4                  1.4.19-2   sed                    4.9-2
boulder             1.0.1-38   gawk                 5.2.2-3   libcxx              16.0.4-7   make                 4.4.1-3   slibtool            0.5.34-4
brotli               1.0.9-3   gdbm                  1.23-2   libcxx-devel        16.0.4-7   moss-container         0.2-5   systemd              252.7-9
bzip2                1.0.8-2   gettext             0.21.1-3   libffi               3.4.4-3   mpfr                 4.2.0-3   util-linux          2.39.3-6
clang               16.0.4-8   gettext-devel       0.21.1-3   libunistring           1.1-1   ncurses                6.4-8   xxhash               0.8.1-5
clang-libs          16.0.4-8   glibc                 2.37-6   libxcrypt           4.4.35-4   nghttp2             1.52.0-3   xz                   5.4.5-8
coreutils              9.3-4   glibc-devel           2.37-6   libxml2             2.10.4-5   nss                   3.94-9   zlib                   1.3-9
curl                 8.5.0-8   gmp                  6.2.1-2   linux-headers       6.4.0-13   openssl              3.1.3-7   zstd                 1.5.5-4
dash                0.5.12-2   grep                  3.11-5   linux-pam            1.5.2-6   pcre2                10.42-3   

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.