-
Notifications
You must be signed in to change notification settings - Fork 124
Description
While working on documentation for using ansi color support, I noticed that ansi.py defines three convenience methods for styling output:
style_success()style_warning()style_error()
These methods are all partial objects created with functools.partial() which supply certain arguments to style(). These methods all behave similarly, I'll give an example for style_error(), but the concept applies to the other methods too.
ansi.style_error() adds ANSI escape sequences to style the message as red text. Say I am creating my own cmd2 based app, and I am following our recommendations to use perror() to output error messages. But I decide in my app I want my error messages to have a yellow background with red text. There are two ways for me to accomplish my objective:
-
override the
perror()method and change the styling applied to the message. The problem with this method is that there are a couple of places inargparse_completer.pyandargparse_custom.pythat callansi.style_error()directly, so those error messages won't match my application's custom error message style. -
redefine
ansi.style_error()so it uses my custom error message color scheme. This makes error messages consistent, but is very brittle and can make my application hard to debug.
Should we consider a different implementation of the "standardizing error, warning, and success text styling" idea that makes it easier for an app developer to override the text coloring we choose to use in cmd2?
One possible approach would be to move style_error() from a function in ansi.py to a method on Cmd2.cmd.