4
4
Execute the taste_the_rainbow command to see the colors available.
5
5
"""
6
6
7
+ import argparse
8
+
7
9
from rich .style import Style
8
10
9
11
import cmd2
10
- from cmd2 .colors import Color
12
+ from cmd2 import (
13
+ Color ,
14
+ stylize ,
15
+ )
11
16
12
17
13
18
class CmdLineApp (cmd2 .Cmd ):
@@ -19,15 +24,16 @@ def __init__(self) -> None:
19
24
self .intro = 'Run the taste_the_rainbow command to see all of the colors available to you in cmd2.'
20
25
21
26
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' )
23
28
24
29
@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 :
26
31
"""Show all of the colors available within cmd2's Color StrEnum class."""
27
32
28
33
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 )
31
37
32
38
33
39
if __name__ == '__main__' :
0 commit comments