summaryrefslogtreecommitdiff
path: root/examples/pirate.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-10-11 15:20:46 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-10-13 17:17:30 -0400
commit55406f89849719c7493b7e7193cb1a0af73ab4fe (patch)
tree4eca765dc7b5883e2489a93dd41759b948f7739d /examples/pirate.py
parente35ab9c169eccc7af3e4ec604e2ddd2e668bdc2c (diff)
downloadcmd2-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/pirate.py')
-rwxr-xr-xexamples/pirate.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/pirate.py b/examples/pirate.py
index 2de832eb..437ee07b 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -8,11 +8,15 @@ It demonstrates many features of cmd2.
"""
import cmd2
-import cmd2.ansi
+from cmd2 import (
+ StdFg,
+)
from cmd2.constants import (
MULTILINE_TERMINATOR,
)
+color_choices = [c.name.lower() for c in StdFg]
+
class Pirate(cmd2.Cmd):
"""A piratical example cmd2 application involving looting and drinking."""
@@ -27,7 +31,7 @@ class Pirate(cmd2.Cmd):
self.songcolor = 'blue'
# Make songcolor settable at runtime
- self.add_settable(cmd2.Settable('songcolor', str, 'Color to ``sing``', self, choices=cmd2.ansi.fg.colors()))
+ self.add_settable(cmd2.Settable('songcolor', str, 'Color to ``sing``', self, choices=color_choices))
# prompts and defaults
self.gold = 0
@@ -72,7 +76,7 @@ class Pirate(cmd2.Cmd):
def do_sing(self, arg):
"""Sing a colorful song."""
- self.poutput(cmd2.ansi.style(arg, fg=self.songcolor))
+ self.poutput(cmd2.ansi.style(arg, fg=StdFg[self.songcolor.upper()]))
yo_parser = cmd2.Cmd2ArgumentParser()
yo_parser.add_argument('--ho', type=int, default=2, help="How often to chant 'ho'")