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.
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 xutils.py 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.
The final improvement is colorizing old and new attributes with the
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(path.name) print(on_blue(tags)) print(on_cyan(renamed_tags), end=DOUBLE_NL)
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.