3131from cmd2 import ansi
3232from plumbum .colors import fg , bg
3333
34- FG_COLORS = {
35- 'black' : fg .Black ,
36- 'red' : fg .DarkRedA ,
37- 'green' : fg .MediumSpringGreen ,
38- 'yellow' : fg .LightYellow ,
39- 'blue' : fg .RoyalBlue1 ,
40- 'magenta' : fg .Purple ,
41- 'cyan' : fg .SkyBlue1 ,
42- 'white' : fg .White ,
43- 'purple' : fg .Purple ,
44- }
45-
46- BG_COLORS = {
47- 'black' : bg .BLACK ,
48- 'red' : bg .DarkRedA ,
49- 'green' : bg .MediumSpringGreen ,
50- 'yellow' : bg .LightYellow ,
51- 'blue' : bg .RoyalBlue1 ,
52- 'magenta' : bg .Purple ,
53- 'cyan' : bg .SkyBlue1 ,
54- 'white' : bg .White ,
55- }
56-
57-
58- def get_fg (fg ):
59- return str (FG_COLORS [fg ])
60-
61-
62- def get_bg (bg ):
63- return str (BG_COLORS [bg ])
34+
35+ class FgColors (ansi .ColorBase ):
36+ black = fg .Black
37+ red = fg .DarkRedA
38+ green = fg .MediumSpringGreen
39+ yellow = fg .LightYellow
40+ blue = fg .RoyalBlue1
41+ magenta = fg .Purple
42+ cyan = fg .SkyBlue1
43+ white = fg .White
44+ purple = fg .Purple
45+
46+
47+ class BgColors (ansi .ColorBase ):
48+ black = bg .BLACK
49+ red = bg .DarkRedA
50+ green = bg .MediumSpringGreen
51+ yellow = bg .LightYellow
52+ blue = bg .RoyalBlue1
53+ magenta = bg .Purple
54+ cyan = bg .SkyBlue1
55+ white = bg .White
56+ purple = bg .Purple
57+
58+
59+ def get_fg (name : str ):
60+ return str (FgColors [name ])
61+
62+
63+ def get_bg (name : str ):
64+ return str (BgColors [name ])
6465
6566
6667ansi .fg_lookup = get_fg
@@ -84,8 +85,8 @@ def __init__(self):
8485 speak_parser .add_argument ('-p' , '--piglatin' , action = 'store_true' , help = 'atinLay' )
8586 speak_parser .add_argument ('-s' , '--shout' , action = 'store_true' , help = 'N00B EMULATION MODE' )
8687 speak_parser .add_argument ('-r' , '--repeat' , type = int , help = 'output [n] times' )
87- speak_parser .add_argument ('-f' , '--fg' , choices = FG_COLORS , help = 'foreground color to apply to output' )
88- speak_parser .add_argument ('-b' , '--bg' , choices = BG_COLORS , help = 'background color to apply to output' )
88+ speak_parser .add_argument ('-f' , '--fg' , choices = FgColors . colors () , help = 'foreground color to apply to output' )
89+ speak_parser .add_argument ('-b' , '--bg' , choices = BgColors . colors () , help = 'background color to apply to output' )
8990 speak_parser .add_argument ('-l' , '--bold' , action = 'store_true' , help = 'bold the output' )
9091 speak_parser .add_argument ('-u' , '--underline' , action = 'store_true' , help = 'underline the output' )
9192 speak_parser .add_argument ('words' , nargs = '+' , help = 'words to say' )
0 commit comments