Missing utility ansi2txt

IPfire core 183.

I miss small utility ansi2txt. That is a filter that removes ANSI colors from output. In Ubuntu, it is included in the package colorized-logs (not installed by default)…

Why? Some programs print colored text to the console and there could be reason to remove colors and see only black/white (plain) text.

Example, pakfire list prints packages in green and red color. When used with grep, it corrupts console, try this: pakfire list | grep ipfire. It is easy to fix console, just execute command reset.

Is there a better way? Yes, use ansi2txt!

pakfire list | ansi2txt | grep ipfire doesn’t corrupt console…

ansi2txt is useful when output from a program, output full of colors, has to be copied to an issue or a plain text file.


Workaround (the good old way):

pakfire list | sed -e 's/\x1b\[[0-9;]*m//g' | grep ipfire
1 Like

Give this a try!

pakfire list --no-colors
[root@ipfire ~] # pakfire --help
Usage: pakfire <install|remove> [options] <pak(s)>
               <update> - Contacts the servers for new lists of paks.
               <upgrade> - Installs the latest version of all paks.
               <list> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks.
               <info> <pak> [<pak> ...] - Output pak metadata.
               <status> - Outputs a summary about available core upgrades, updates and a required reboot

       Global options:
               --non-interactive --> Enables the non-interactive mode.
                                     You won't see any question here.
                              -y --> Short for --non-interactive.
                     --no-colors --> Turns off the wonderful colors.

[root@ipfire ~] # 
1 Like

OK, I assume it works. But no all programs have an option to disable colors. ansi2txt is a filter that works for any program… pakfire was my example as I know it has output with colors and I do not like it… :wink:

Another example, log file has color codes:

[root@ipfire ~]# head /var/log/pakfire/update-core-upgrade-183.log
Stopping strongSwan IPsec failed: starter is not running
Stopping Apache daemon...                                                                                                                                     [  OK  ]
Stopping SSH Server...                                                                                                                                        [ FAIL ]
removed '/boot/System.map-6.1.61-ipfire'
removed '/boot/config-6.1.61-ipfire'
removed '/boot/initramfs-6.1.61-ipfire.img'
removed '/boot/vmlinuz-6.1.61-ipfire'
...
[root@ipfire ~]# less /var/log/pakfire/update-core-upgrade-183.log
Stopping strongSwan IPsec failed: starter is not running
Stopping Apache daemon...
ESC[1AESC[0GESC[159GESC[1;34m[ESC[1;32m  OK  ESC[1;34m]ESC[0;39m
ESC[1AESC[0GESC[159GESC[1;34m[ESC[1;32m  OK  ESC[1;34m]ESC[0;39m
Stopping SSH Server...
ESC[1AESC[0GESC[159GESC[1;34m[ESC[1;31m FAIL ESC[1;34m]ESC[0;39m
removed '/boot/System.map-6.1.61-ipfire'
removed '/boot/config-6.1.61-ipfire'
...

For the most part this is not an issue for me so I don’t have a good solution.

Since the support & build queues are very busy I’d suggest using this as an opportunity to learn how to build an IPFire add-on. It always helps to have a first project that you are passionate about. And this one seems to be it!

There are people within the Community that can help (and are willing to help!)

This can get you started:

-and-

2 Likes