summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-19 15:32:37 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-19 15:32:37 -0400
commitccbe1276f786e94f1996877fdec6d070705f5ab8 (patch)
tree167fe848ea36915091fbc7cbd7ad1032dd4474ec /examples
parentf787b1fb0adc8596d338af9cebdf3866e75fdbaa (diff)
downloadcmd2-git-ccbe1276f786e94f1996877fdec6d070705f5ab8.tar.gz
cmd2.Cmd.__init__ now initializes colorama and tells it to never strip ANSI codes since cmd2 deals with that
Also: - Finished editing poutput(), ppaged(), and pfeedback() methods to strip ANSI color when appropriate - Changed attr.ib() factory usage so cmd2 is compatible with older versions of attrs
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/colors.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/examples/colors.py b/examples/colors.py
index 59e108b6..fb2de045 100755
--- a/examples/colors.py
+++ b/examples/colors.py
@@ -53,6 +53,7 @@ BG_COLORS ={
'white':Back.WHITE,
}
+
class CmdLineApp(cmd2.Cmd):
"""Example cmd2 application demonstrating colorized output."""
@@ -71,14 +72,14 @@ class CmdLineApp(cmd2.Cmd):
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
- super().__init__(use_ipython=False)
+ super().__init__(use_ipython=True)
speak_parser = argparse.ArgumentParser()
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', help='foreground color to apply to output')
- speak_parser.add_argument('-b', '--bg', help='background color to apply to output')
+ speak_parser.add_argument('-f', '--fg', choices=FG_COLORS, help='foreground color to apply to output')
+ speak_parser.add_argument('-b', '--bg', choices=BG_COLORS, help='background color to apply to output')
speak_parser.add_argument('words', nargs='+', help='words to say')
@cmd2.with_argparser(speak_parser)
@@ -95,9 +96,9 @@ class CmdLineApp(cmd2.Cmd):
repetitions = args.repeat or 1
color_on = ''
- if args.fg and args.fg in FG_COLORS:
+ if args.fg:
color_on += FG_COLORS[args.fg]
- if args.bg and args.bg in BG_COLORS:
+ if args.bg:
color_on += BG_COLORS[args.bg]
color_off = Fore.RESET + Back.RESET