nikolassv / bartib

A simple timetracker for the command line. It saves a log of all tracked activities as a plaintext file and allows you to create flexible reports.
GNU General Public License v3.0
685 stars 36 forks source link

Ability to disable ansi codes #58

Open Spiegie opened 5 days ago

Spiegie commented 5 days ago

It would be nice to disable bold printing in Report and where it is also implemented. I Think, this should be possible by passing a --no-bold flag or something to bartib itself not its subcommands or should be configurable with env-var.

I'm using Bartib in other Programs and the bold-formatting messes with my output-strings.

nikolassv commented 5 days ago

This sounds like a useful enhancement. The ansi codes in the output do indeed complicate using the output in other programs. I would even suggest to create a new parameter --no-color which prevents all ansi codes for colors and text formatting.

Spiegie commented 4 days ago

how would you implement it? Should i implement a function wrapping the bold function inside an own function that implements Style? This wrapper than contains logic about if the style is desired by the user? I would go as far as disabling color bold and all other ansi codes all together with a --plain or --artless flag.

What I dont like about this approach is, that i would have to wrap every style funktion, that messes with ansi codes. Can you hint me to a better solution?

Spiegie commented 4 days ago

for everyone who struggles with this, here is a workaround in Python https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python. Its a regex, so it should be easy to apply to your needs. nonetheless I think, my proposal is useful.

nikolassv commented 3 hours ago

I am unsure about the best solution, too. The style hints are used in several places in the view module without any abstraction.

Your suggestion sound viable to me. Would you give it a try and see how it works out?