Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/color-print.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Add color to console print statements.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
27 changes: 20 additions & 7 deletions src/diffpy/cmi/packsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand All @@ -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}")

Expand Down
9 changes: 4 additions & 5 deletions src/diffpy/cmi/profilesmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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:
Expand Down
16 changes: 7 additions & 9 deletions tests/test_packsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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""",
Expand Down
8 changes: 4 additions & 4 deletions tests/test_profilesmanager.py
Original file line number Diff line number Diff line change
@@ -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
""",
),
Expand Down
Loading