From 81bbcdd97cb60e3238bb13dee2e08134b72eaed8 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Thu, 20 Nov 2025 11:58:48 -0500 Subject: [PATCH 1/3] add colors to print statements --- src/diffpy/cmi/packsmanager.py | 27 ++++++++++++++++++++------- src/diffpy/cmi/profilesmanager.py | 9 ++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/diffpy/cmi/packsmanager.py b/src/diffpy/cmi/packsmanager.py index e85a3e4..dc7f5c4 100644 --- a/src/diffpy/cmi/packsmanager.py +++ b/src/diffpy/cmi/packsmanager.py @@ -28,6 +28,20 @@ __all__ = ["PacksManager", "get_package_dir"] +class Styles: + RESET = "\033[0m" + # styles + BOLD = "\033[1m" + UNDER = "\033[4m" + # colors + RED = "\033[31m" + GREEN = "\033[32m" + YELLOW = "\033[33m" + BLUE = "\033[34m" + MAGENTA = "\033[35m" + CYAN = "\033[36m" + + def get_package_dir(root_path=None): """Get the package directory as a context manager. @@ -353,20 +367,19 @@ def install_pack(self, identifier: str | Path) -> None: def print_packs(self) -> None: """Print information about available packs.""" uninstalled_packs, installed_packs = [], [] + s = Styles() for pack in self.available_packs(): if self.check_pack(pack): installed_packs.append(pack) else: uninstalled_packs.append(pack) - print("Installed Packs:") - print("----------------") + print(f"{s.BOLD}{s.UNDER}{s.BLUE}Installed Packs:{s.RESET}") for pack in installed_packs: if not installed_packs: print(" (none)") else: print(f" {pack}") - print("\nAvailable Packs:") - print("----------------") + print(f"\n{s.BOLD}{s.UNDER}{s.BLUE}Available Packs:{s.RESET}") if not uninstalled_packs: print(" (all packs installed)") else: @@ -375,11 +388,11 @@ def print_packs(self) -> None: def print_examples(self) -> None: """Print information about available examples.""" - print("\nExamples:") - print("---------") + s = Styles() + print(f"\n{s.BOLD}{s.UNDER}{s.CYAN}Examples:{s.RESET}") examples_dict = self.available_examples() for pack, examples in examples_dict.items(): - print(f" {pack}:") + print(f" {s.BOLD}{pack}:{s.RESET}") for ex_name, _ in examples: print(f" - {ex_name}") diff --git a/src/diffpy/cmi/profilesmanager.py b/src/diffpy/cmi/profilesmanager.py index 090d4f7..c88b5c9 100644 --- a/src/diffpy/cmi/profilesmanager.py +++ b/src/diffpy/cmi/profilesmanager.py @@ -26,7 +26,7 @@ presence_check, ) from diffpy.cmi.log import plog -from diffpy.cmi.packsmanager import PacksManager, get_package_dir +from diffpy.cmi.packsmanager import PacksManager, Styles, get_package_dir __all__ = ["Profile", "ProfilesManager"] @@ -234,21 +234,20 @@ def install(self, identifier: Union[str, Path]) -> None: def print_profiles(self) -> None: """Print available and installed profiles.""" + s = Styles() installed_profiles, uninstalled_profiles = [], [] for profile_name in self.available_profiles(): if self.check_profile(profile_name): installed_profiles.append(profile_name) else: uninstalled_profiles.append(profile_name) - print("\nInstalled Profiles:") - print("-------------------") + print(f"\n{s.BOLD}{s.UNDER}{s.MAGENTA}Installed Profiles:{s.RESET}") if not installed_profiles: print(" (none)") else: for profile in installed_profiles: print(f" {profile}") - print("\nAvailable Profiles:") - print("-------------------") + print(f"\n{s.BOLD}{s.UNDER}{s.MAGENTA}Available Profiles:{s.RESET}") if not uninstalled_profiles: print(" (all profiles installed)") else: From 668b921e8ed766dcf51013f48b0cd85a02e8f39d Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Thu, 20 Nov 2025 11:59:41 -0500 Subject: [PATCH 2/3] update tests to accept color --- tests/test_packsmanager.py | 16 +++++++--------- tests/test_profilesmanager.py | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/test_packsmanager.py b/tests/test_packsmanager.py index 1a87737..61813d2 100644 --- a/tests/test_packsmanager.py +++ b/tests/test_packsmanager.py @@ -5,7 +5,7 @@ import pytest from diffpy.cmi import installer -from diffpy.cmi.packsmanager import PacksManager +from diffpy.cmi.packsmanager import PacksManager, Styles def paths_and_names_match(expected, actual, root): @@ -345,24 +345,22 @@ def test_copy_examples_force(example_cases, expected_paths, force): assert copied_path.read_text() == original_path.read_text() +s = Styles() install_params = [ ( # input: packs to install # expected: output showing packA installed but not packB ("packA",), - """Installed Packs: ----------------- + f"""{s.BOLD}{s.UNDER}{s.BLUE}Installed Packs:{s.RESET} packA -Available Packs: ----------------- +{s.BOLD}{s.UNDER}{s.BLUE}Available Packs:{s.RESET} packB -Examples: ---------- - packA: +{s.BOLD}{s.UNDER}{s.CYAN}Examples:{s.RESET} + {s.BOLD}packA:{s.RESET} - ex1 - ex2 - packB: + {s.BOLD}packB:{s.RESET} - ex1 - ex3 - ex4""", diff --git a/tests/test_profilesmanager.py b/tests/test_profilesmanager.py index 51bd328..a9656c5 100644 --- a/tests/test_profilesmanager.py +++ b/tests/test_profilesmanager.py @@ -1,19 +1,19 @@ import pytest import yaml +from diffpy.cmi.packsmanager import Styles from diffpy.cmi.profilesmanager import ProfilesManager +s = Styles() install_params = [ ( # input: profiles to install # expected: print_profile output showing profileA # installed but not profileB ("profileA",), - """Installed Profiles: -------------------- + f"""{s.BOLD}{s.UNDER}{s.MAGENTA}Installed Profiles:{s.RESET} profileA -Available Profiles: -------------------- +{s.BOLD}{s.UNDER}{s.MAGENTA}Available Profiles:{s.RESET} profileB """, ), From f099e746c794e30581d9b29e5f5a4b73e2ad008c Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Thu, 20 Nov 2025 12:00:14 -0500 Subject: [PATCH 3/3] news --- news/color-print.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/color-print.rst diff --git a/news/color-print.rst b/news/color-print.rst new file mode 100644 index 0000000..20e05e0 --- /dev/null +++ b/news/color-print.rst @@ -0,0 +1,23 @@ +**Added:** + +* Add color to console print statements. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +*