summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-02-06 22:50:00 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2020-02-06 22:50:00 -0500
commite66dc6f7078e1d4928ef58ccf48f4718b61d8c35 (patch)
treeefbdf93ee7c44acce04cd6758eee4c155838001f /examples
parentede9f3e77a59281a442227ed9b4b92e62e85d2b9 (diff)
downloadcmd2-git-e66dc6f7078e1d4928ef58ccf48f4718b61d8c35.tar.gz
Having two parallel datastructures each for foreground and background colors felt really clunky - now we just have one
The Enum classes are now smart and deal with it all.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/colors.py4
-rwxr-xr-xexamples/initialization.py7
-rwxr-xr-xexamples/pirate.py2
3 files changed, 6 insertions, 7 deletions
diff --git a/examples/colors.py b/examples/colors.py
index 33b17e53..1466471b 100755
--- a/examples/colors.py
+++ b/examples/colors.py
@@ -48,8 +48,8 @@ class CmdLineApp(cmd2.Cmd):
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
speak_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
- speak_parser.add_argument('-f', '--fg', choices=ansi.FG_COLORS, help='foreground color to apply to output')
- speak_parser.add_argument('-b', '--bg', choices=ansi.BG_COLORS, help='background color to apply to output')
+ speak_parser.add_argument('-f', '--fg', choices=ansi.fg.colors(), help='foreground color to apply to output')
+ speak_parser.add_argument('-b', '--bg', choices=ansi.bg.colors(), help='background color to apply to output')
speak_parser.add_argument('-l', '--bold', action='store_true', help='bold the output')
speak_parser.add_argument('-u', '--underline', action='store_true', help='underline the output')
speak_parser.add_argument('words', nargs='+', help='words to say')
diff --git a/examples/initialization.py b/examples/initialization.py
index c13ed137..609255f1 100755
--- a/examples/initialization.py
+++ b/examples/initialization.py
@@ -13,8 +13,7 @@
10) How to make custom attributes settable at runtime
"""
import cmd2
-from cmd2 import style
-from cmd2.ansi import FG_COLORS
+from cmd2 import style, fg, bg
class BasicApp(cmd2.Cmd):
@@ -25,7 +24,7 @@ class BasicApp(cmd2.Cmd):
startup_script='scripts/startup.txt', use_ipython=True)
# Prints an intro banner once upon application startup
- self.intro = style('Welcome to cmd2!', fg='red', bg='white', bold=True)
+ self.intro = style('Welcome to cmd2!', fg=fg.red, bg=bg.white, bold=True)
# Show this as the prompt when asking for input
self.prompt = 'myapp> '
@@ -44,7 +43,7 @@ class BasicApp(cmd2.Cmd):
# Make echo_fg settable at runtime
self.add_settable(cmd2.Settable('foreground_color', str, 'Foreground color to use with echo command',
- choices=FG_COLORS))
+ choices=fg.colors()))
@cmd2.with_category(CUSTOM_CATEGORY)
def do_intro(self, _):
diff --git a/examples/pirate.py b/examples/pirate.py
index acbab17c..a50f9a51 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -25,7 +25,7 @@ class Pirate(cmd2.Cmd):
self.songcolor = 'blue'
# Make songcolor settable at runtime
- self.add_settable(cmd2.Settable('songcolor', str, 'Color to ``sing``', choices=cmd2.ansi.FG_COLORS))
+ self.add_settable(cmd2.Settable('songcolor', str, 'Color to ``sing``', choices=cmd2.ansi.fg.colors()))
# prompts and defaults
self.gold = 0