LLL
LLL

Reputation: 1907

How to color console output of a custom program

Problem:

I'm using Terminator but I think this question is relevant to any terminal. To be more precise let me please explain my problem on concrete example. I'm running Android cts tests, so I need to use cts-tradef script. This is how it looks like:

enter image description here

The script just runs jar (which I don't want to modify), however I would like to change color of cts-tf, so it looks like on a picture below:

enter image description here

My unsuccessful attempts to solve the problem:

For now I've tried doing something like this:

echo -e "\033[01;32m" && ./cts-tradefed

However it will color everything (as on below picture) while I want to color only cts-tf string (as above):

enter image description here

I also tried using sed, however although it works and replace some strings it also finishes cts-tradefed, so it's useless to me. Same thing (cts-tradefed finishes) happens when piping it through grep:

./cts-tradefed | grep --color "cts-tf\|$"

Another try was with grc tool mentioned by Anthony Geoghegan. Running it without config file doesn't do anything but cts-tradefed doesn't finish but when I run it with config file cts-tradefed finishes the same as with grep or sed. My config file was ok, since it works good with cat or similar commands.

Upvotes: 1

Views: 157

Answers (1)

Anthony Geoghegan
Anthony Geoghegan

Reputation: 11993

I haven’t used it myself but Radovan Garabík’s Generic Colouriser looks like it should do what you want. It’s written in Python “for beautifying your logfiles or output of commands”.

Packages are available for Debian-based operating systems but I imagine it should not be too hard to install if you are familiar with Python.

GitHub repository

Upvotes: 1

Related Questions