diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-10-11 15:20:46 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-10-13 17:17:30 -0400 |
commit | 55406f89849719c7493b7e7193cb1a0af73ab4fe (patch) | |
tree | 4eca765dc7b5883e2489a93dd41759b948f7739d /examples/initialization.py | |
parent | e35ab9c169eccc7af3e4ec604e2ddd2e668bdc2c (diff) | |
download | cmd2-git-extended_colors.tar.gz |
Added support for 8-bit/256-colors with the cmd2.EightBitFg and cmd2.EightBitBg classes.extended_colors
Added support for 24-bit/RGB colors with the cmd2.RgbFg and cmd2.RgbBg classes.
Removed dependency on colorama.
Deprecated cmd2.fg. Use cmd2.StdFg instead.
Deprecated cmd2.bg. Use cmd2.StdBg instead.
Changed type of ansi.allow_style from a string to an ansi.AllowStyle Enum class.
Fixed bug where using choices on a Settable didn't verify that a valid choice had been entered.
Diffstat (limited to 'examples/initialization.py')
-rwxr-xr-x | examples/initialization.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/initialization.py b/examples/initialization.py index dfea2183..375711ff 100755 --- a/examples/initialization.py +++ b/examples/initialization.py @@ -14,8 +14,8 @@ """ import cmd2 from cmd2 import ( - bg, - fg, + StdBg, + StdFg, style, ) @@ -32,7 +32,7 @@ class BasicApp(cmd2.Cmd): ) # Prints an intro banner once upon application startup - self.intro = style('Welcome to cmd2!', fg=fg.red, bg=bg.white, bold=True) + self.intro = style('Welcome to cmd2!', fg=StdFg.RED, bg=StdBg.WHITE, bold=True) # Show this as the prompt when asking for input self.prompt = 'myapp> ' @@ -47,11 +47,12 @@ class BasicApp(cmd2.Cmd): self.default_category = 'cmd2 Built-in Commands' # Color to output text in with echo command - self.foreground_color = 'cyan' + self.foreground_color = StdFg.CYAN.name.lower() # Make echo_fg settable at runtime + fg_colors = [c.name.lower() for c in StdFg] self.add_settable( - cmd2.Settable('foreground_color', str, 'Foreground color to use with echo command', self, choices=fg.colors()) + cmd2.Settable('foreground_color', str, 'Foreground color to use with echo command', self, choices=fg_colors) ) @cmd2.with_category(CUSTOM_CATEGORY) @@ -62,7 +63,8 @@ class BasicApp(cmd2.Cmd): @cmd2.with_category(CUSTOM_CATEGORY) def do_echo(self, arg): """Example of a multiline command""" - self.poutput(style(arg, fg=self.foreground_color)) + fg_color = StdFg[self.foreground_color.upper()] + self.poutput(style(arg, fg=fg_color)) if __name__ == '__main__': |