From f91ccf2bb28531f9d1dee551314cb091fa57df74 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Thu, 27 Jun 2019 23:54:07 -0400 Subject: Simplified ansi color dictionaries and lookup methods Also: - Updated examples that use color to use cmd2.ansi instead of colorama - Updated tests that use color to use cmd2.ansi instead of colorama - plumbum_colorspy example shows how to override color lookup functions to use a different color library --- examples/async_printing.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'examples/async_printing.py') diff --git a/examples/async_printing.py b/examples/async_printing.py index 3089070f..b3618475 100755 --- a/examples/async_printing.py +++ b/examples/async_printing.py @@ -4,15 +4,13 @@ A simple example demonstrating an application that asynchronously prints alerts, updates the prompt and changes the window title """ - import random import threading import time from typing import List -from colorama import Fore - import cmd2 +from cmd2 import ansi ALERTS = ["Watch as this application prints alerts and updates the prompt", "This will only happen when the prompt is present", @@ -141,26 +139,12 @@ class AlerterApp(cmd2.Cmd): return alert_str def _generate_colored_prompt(self) -> str: - """ - Randomly generates a colored prompt + """Randomly generates a colored prompt :return: the new prompt """ - rand_num = random.randint(1, 20) - - status_color = Fore.RESET - - if rand_num == 1: - status_color = Fore.LIGHTRED_EX - elif rand_num == 2: - status_color = Fore.LIGHTYELLOW_EX - elif rand_num == 3: - status_color = Fore.CYAN - elif rand_num == 4: - status_color = Fore.LIGHTGREEN_EX - elif rand_num == 5: - status_color = Fore.LIGHTBLUE_EX - - return status_color + self.visible_prompt + Fore.RESET + fg_color = random.choice(list(ansi.FG_COLORS.keys())) + bg_color = random.choice(list(ansi.BG_COLORS.keys())) + return ansi.style(self.visible_prompt, fg=fg_color, bg=bg_color) def _alerter_thread_func(self) -> None: """ Prints alerts and updates the prompt any time the prompt is showing """ -- cgit v1.2.1