44Execute the taste_the_rainbow command to see the colors available.
55"""
66
7+ import argparse
8+
79from rich .style import Style
810
911import cmd2
10- from cmd2 .colors import Color
12+ from cmd2 import (
13+ Color ,
14+ stylize ,
15+ )
1116
1217
1318class CmdLineApp (cmd2 .Cmd ):
@@ -19,15 +24,16 @@ def __init__(self) -> None:
1924 self .intro = 'Run the taste_the_rainbow command to see all of the colors available to you in cmd2.'
2025
2126 rainbow_parser = cmd2 .Cmd2ArgumentParser ()
22- rainbow_parser .add_argument ('-b' , '--background' , action = 'store_true' , help = 'Show background colors as well' )
27+ rainbow_parser .add_argument ('-b' , '--background' , action = 'store_true' , help = 'show background colors as well' )
2328
2429 @cmd2 .with_argparser (rainbow_parser )
25- def do_taste_the_rainbow (self , args ) -> None :
30+ def do_taste_the_rainbow (self , args : argparse . Namespace ) -> None :
2631 """Show all of the colors available within cmd2's Color StrEnum class."""
2732
2833 for color_member in Color :
29- style = Style (bgcolor = color_member .value ) if args .background else Style (color = color_member .value )
30- self .poutput (f"{ color_member .name } " , style = style , soft_wrap = False )
34+ style = Style (bgcolor = color_member ) if args .background else Style (color = color_member )
35+ styled_name = stylize (color_member .name , style = style )
36+ self .poutput (styled_name )
3137
3238
3339if __name__ == '__main__' :
0 commit comments