Colorize printed text to get eyes focused. Termcolor

Working with extended file attributes , i have to do many necessary operations. Updating attributes goes through a search by scanning their values, filtering them and then setting new values up.

During this process mistakes can be easily made, therefore, a few helpful steps of advanced text printing are worth doing for checking the result is correct.

Text formatting and colorizing are good choices for improving understanding of printed initial and final attributes text, termcolor helps with it.

Plain text

What does printed plain text look like? It's a line that i read and split up on logic parts in mind. When those lines are hundreds such a way of reading frustrates me while scrolling up and down.

$ python rename-tags --from '[n]' --to '[new-t]' files-dir

Where to look at here?

The first thing i improved is formatting the line as a column with a blank line separator at the bottom.

Nice, cluttering is gone, only one thing at a time as a column of the file name, old attributes, new attributes and separator.

Colored text

The final improvement is colorizing old and new attributes with the colored() function.

Example snippet

from termcolor import colored

DOUBLE_NL = '\n\n'
on_blue = lambda text: colored(text, 'grey', on_color='on_blue', attrs=['bold'])
on_cyan = lambda text: colored(text, 'grey', on_color='on_cyan', attrs=['bold'])

print(on_cyan(renamed_tags), end=DOUBLE_NL)
Before After

Colors point my eyes to two lines below a file name to see a difference only and conclude whether renaming is correct.

Time is payed for colorization small, but effect is big. No complicated libraries are used.


Termcolor is very basic, but simple to use and gives a wide range of flexibility. There are a few others, two of them i'd like to recommend are colorama and rich .