summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-02-07 17:04:24 -0500
committerGitHub <noreply@github.com>2020-02-07 17:04:24 -0500
commit5def049472e1c261ad78ff56c5d5b3c6332e9bab (patch)
tree9750793bab06c519362712ee3e4c56ff7c7fc662 /examples
parent3f075900264fee32c356aac3d03b2568664ba684 (diff)
parent715af6059d06521c8f0054007a1105d211402d63 (diff)
downloadcmd2-git-5def049472e1c261ad78ff56c5d5b3c6332e9bab.tar.gz
Merge pull request #877 from python-cmd2/changelog_fix
Changelog fix for removed ansi.FG_COLORS and ansi.BG_COLORS
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/async_printing.py16
-rwxr-xr-xexamples/plumbum_colors.py65
2 files changed, 41 insertions, 40 deletions
diff --git a/examples/async_printing.py b/examples/async_printing.py
index fdba14a0..692ce769 100755
--- a/examples/async_printing.py
+++ b/examples/async_printing.py
@@ -10,7 +10,7 @@ import time
from typing import List
import cmd2
-from cmd2 import ansi
+from cmd2 import style, fg
ALERTS = ["Watch as this application prints alerts and updates the prompt",
"This will only happen when the prompt is present",
@@ -145,20 +145,20 @@ class AlerterApp(cmd2.Cmd):
"""
rand_num = random.randint(1, 20)
- status_color = 'reset'
+ status_color = fg.reset
if rand_num == 1:
- status_color = 'bright_red'
+ status_color = fg.bright_red
elif rand_num == 2:
- status_color = 'bright_yellow'
+ status_color = fg.bright_yellow
elif rand_num == 3:
- status_color = 'cyan'
+ status_color = fg.cyan
elif rand_num == 4:
- status_color = 'bright_green'
+ status_color = fg.bright_green
elif rand_num == 5:
- status_color = 'bright_blue'
+ status_color = fg.bright_blue
- return ansi.style(self.visible_prompt, fg=status_color)
+ return style(self.visible_prompt, fg=status_color)
def _alerter_thread_func(self) -> None:
""" Prints alerts and updates the prompt any time the prompt is showing """
diff --git a/examples/plumbum_colors.py b/examples/plumbum_colors.py
index 94815f50..2887ef1f 100755
--- a/examples/plumbum_colors.py
+++ b/examples/plumbum_colors.py
@@ -31,36 +31,37 @@ import cmd2
from cmd2 import ansi
from plumbum.colors import fg, bg
-FG_COLORS = {
- 'black': fg.Black,
- 'red': fg.DarkRedA,
- 'green': fg.MediumSpringGreen,
- 'yellow': fg.LightYellow,
- 'blue': fg.RoyalBlue1,
- 'magenta': fg.Purple,
- 'cyan': fg.SkyBlue1,
- 'white': fg.White,
- 'purple': fg.Purple,
-}
-
-BG_COLORS = {
- 'black': bg.BLACK,
- 'red': bg.DarkRedA,
- 'green': bg.MediumSpringGreen,
- 'yellow': bg.LightYellow,
- 'blue': bg.RoyalBlue1,
- 'magenta': bg.Purple,
- 'cyan': bg.SkyBlue1,
- 'white': bg.White,
-}
-
-
-def get_fg(fg):
- return str(FG_COLORS[fg])
-
-
-def get_bg(bg):
- return str(BG_COLORS[bg])
+
+class FgColors(ansi.ColorBase):
+ black = fg.Black
+ red = fg.DarkRedA
+ green = fg.MediumSpringGreen
+ yellow = fg.LightYellow
+ blue = fg.RoyalBlue1
+ magenta = fg.Purple
+ cyan = fg.SkyBlue1
+ white = fg.White
+ purple = fg.Purple
+
+
+class BgColors(ansi.ColorBase):
+ black = bg.BLACK
+ red = bg.DarkRedA
+ green = bg.MediumSpringGreen
+ yellow = bg.LightYellow
+ blue = bg.RoyalBlue1
+ magenta = bg.Purple
+ cyan = bg.SkyBlue1
+ white = bg.White
+ purple = bg.Purple
+
+
+def get_fg(name: str):
+ return str(FgColors[name])
+
+
+def get_bg(name: str):
+ return str(BgColors[name])
ansi.fg_lookup = get_fg
@@ -84,8 +85,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=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('-f', '--fg', choices=FgColors.colors(), help='foreground color to apply to output')
+ speak_parser.add_argument('-b', '--bg', choices=BgColors.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')