erikrose/blessings — Issue #8: Validation for formatters
Author: erikrose
Created: 2011-11-19 21:56:13+00:00
State: open
Labels: enhancement

Provide a way to test whether a formatter (like "green", "red_on_green", "bold", or "bold_underline_on_white") is valid so we can take them from the commandline without worrying about having a TypeError deep down later. The easy way would be to add an `is_formatter` attribute to FormattingString that would always be true and one to ParametrizingString that would always be False.

if not getattr(term, 'bold_underline_whatever').is_formatter:
raise Kaboom("You lose at command-lining.")

That would save making FormattingString public just so folks can do isinstance() calls against it.

The downside to this is that we'd need to have the Terminal around during configuration, or else we'd have to gracefully raise config errors later, after it's been constructed, which I could see being clumsy in some apps.

Maybe we do need a top-level is_valid_formatter()-type thing after all.