HorlogeSkynet / archey4

:computer: Maintained fork of the original Archey (Linux) system tool
https://git.io/archey4
GNU General Public License v3.0
291 stars 37 forks source link

[BUG] How to write to a file with colors? #155

Closed dracorp closed 1 month ago

dracorp commented 1 month ago

Describe the bug

I would like to use archey to create motd. But when I redirect the output to a file, the colors are missing. The same is for tee command.

Expected behavior

The colors should be kept. As for neofetch. The neofetch uses ascii escape:

cat -v /etc/motd
^[[?25l^[[?7l^[[0m^[[32m^[[1m ____^[[0m^[[33m^[[1m^^[[0m^[[35m^[[1m____
^[[0m^[[32m^[[1m |\  ^[[0m^[[33m^[[1m|^[[0m^[[35m^[[1m  /|
^[[0m^[[32m^[[1m | \ ^[[0m^[[33m^[[1m|^[[0m^[[35m^[[1m / |
^[[0m^[[35m^[[1m<---- ^[[0m^[[34m^[[1m---->
^[[0m^[[34m^[[1m | / ^[[0m^[[32m^[[1m|^[[0m^[[33m^[[1m \ |
^[[0m^[[34m^[[1m |/__^[[0m^[[32m^[[1m|^[[0m^[[33m^[[1m__\|
^[[0m^[[32m^[[1m     v^[[0m
^[[7A^[[9999999D^[[14C^[[0m^[[1m^[[33m^[[1mgdndev114.dev.lsy.pl^[[0m
^[[14C^[[0m--------------------^[[0m
^[[14C^[[0m^[[32m^[[1mOS^[[0m^[[0m:^[[0m CentOS Linux 7 (Core) x86_64^[[0m
^[[14C^[[0m^[[32m^[[1mKernel^[[0m^[[0m:^[[0m Linux 3.10.0-957.12.1.el7.x86_64^[[0m
^[[14C^[[0m^[[32m^[[1mCPU^[[0m^[[0m:^[[0m Intel Xeon E5-2695 v4 (16) @ 2.0GHz^[[0m
^[[14C^[[0m^[[32m^[[1mMemory^[[0m^[[0m:^[[0m 3.99GiB / 15.51GiB^[[0m

Screenshots

image

Environment

Additional context

Custom configuration

Custom configuration

```json { "allow_overriding": true, "parallel_loading": true, "suppress_warnings": false, "entries_color": "", "honor_ansi_color": false, "logo_style": "", "entries_icon": false, "entries": [ { "type": "Hostname" }, { "type": "Distro" }, { "type": "Kernel", "check_version": false }, { "type": "CPU", "one_line": false, "show_cores": true }, { "type": "RAM", "warning_use_percent": 33.3, "danger_use_percent": 66.7 }, { "type": "Disk", "show_filesystems": ["local"], "combine_total": true, "disk_labels": null, "hide_entry_name": null, "warning_use_percent": 50, "danger_use_percent": 75 }, { "type": "LAN_IP", "one_line": true, "max_count": 1, "show_global": false, "show_link_local": true, "ipv6_support": false } ], "default_strings": { "latest": "latest", "available": "available", "no_address": "No Address", "not_detected": "Not detected", "virtual_environment": "Virtual Environment" } } ```

HorlogeSkynet commented 1 month ago

Hello @dracorp, Archey automatically detects whether output is a TTY to display colors. You can set CLICOLOR_FORCE=1 as environment variable to keep colors in your case. Bye :wave:

dracorp commented 1 month ago

Thank you. I did not find this option.

HorlogeSkynet commented 1 month ago

You're very welcome. It's actually documented in the manual page (which only gets installed in Linux distribution packages (see archey.1), but not through pip)...