Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Implement Color/Style helper
Browse files Browse the repository at this point in the history
This helper is supposed to format text color/style in cases where rich
cannot be used (exceptions for example)
  • Loading branch information
JakubFrejlach committed Nov 13, 2023
1 parent 6eaed9b commit b160d33
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
18 changes: 10 additions & 8 deletions griffon/commands/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
generate_entity_report,
generate_license_report,
)
from griffon.helpers import Style
from griffon.output import (
console,
cprint,
Expand Down Expand Up @@ -188,12 +189,12 @@ def retrieve_component_summary(ctx, component_name, strict_name_search):
# @click.option(
# "--cve-id",
# "cve_id",
# help="Attach affects to this (\033[1mCVE-ID\033[0m).",
# help=f"Attach affects to this {Style.BOLD}CVE-ID{Style.RESET}.",
# )
@click.option(
"--sfm2-flaw-id",
"sfm2_flaw_id",
help="Attach affects to this (\033[1msfm2 flaw id\033[0m).",
help=f"Attach affects to this {Style.BOLD}sfm2 flaw id{Style.RESET}.",
)
@click.option(
"--flaw-mode",
Expand All @@ -207,28 +208,28 @@ def retrieve_component_summary(ctx, component_name, strict_name_search):
"search_latest",
is_flag=True,
default=False,
help="Search root Components (\033[1menabled by default\033[0m).",
help=f"Search root Components {Style.BOLD}(enabled by default){Style.RESET}.",
)
@click.option(
"--search-provides",
"search_provides",
is_flag=True,
default=False,
help="Search root Components by provides children(\033[1menabled by default\033[0m).",
help=f"Search root Components by provides children {Style.BOLD}(enabled by default){Style.RESET}.",
)
@click.option(
"--search-upstreams",
"search_upstreams",
is_flag=True,
default=False,
help="Search root Components by upstreams children (\033[1menabled by default\033[0m).",
help=f"Search root Components by upstreams children {Style.BOLD}(enabled by default){Style.RESET}.",
)
@click.option(
"--search-related-url",
"search_related_url",
is_flag=True,
default=False,
help="Search related url (\033[1menabled by default\033[0m).",
help=f"Search related url {Style.BOLD}(enabled by default){Style.RESET}.",
)
@click.option(
"--filter-rh-naming",
Expand Down Expand Up @@ -357,7 +358,7 @@ def get_product_contain_component(
if not purl and not component_name:
click.echo(ctx.get_help())
click.echo("")
click.echo("\033[1mMust supply Component name or --purl.\033[0m")
click.echo(f"{Style.BOLD}Must supply Component name or --purl.{Style.RESET}")
exit(0)

if (
Expand Down Expand Up @@ -576,7 +577,8 @@ def get_product_contain_component(
else:
console.print("Flaw is not missing any affect entries")

ctx.exit()
# ctx.exit()
return

cprint(q, ctx=ctx)

Expand Down
45 changes: 45 additions & 0 deletions griffon/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Helpers for direct usage or debbuging
"""
import json
from enum import Enum
from typing import Callable, Optional, Type, Union

from component_registry_bindings.bindings.python_client.types import (
Expand Down Expand Up @@ -61,3 +62,47 @@ def debug_data_load(
else:
data = json_data
return data


class Color(Enum):
"""
Helper enum for text color formatting for anything which
cannot be rendered using rich
"""

BLACK = "\033[30m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
WHITE = "\033[37m"
GREY = "\033[90m"
BRIGHT_RED = "\033[91m"
BRIGHT_GREEN = "\033[92m"
BRIGHT_YELLOW = "\033[93m"
BRIGHT_BLUE = "\033[94m"
BRIGHT_MAGENTA = "\033[95m"
BRIGHT_CYAN = "\033[96m"
BRIGHT_WHITE = "\033[97m"
RESET = "\033[0m" # Reset to default color and style

def __str__(self):
return str(self.value)


class Style(Enum):
"""
Helper enum for text style formatting for anything which
cannot be rendered using rich
"""

BOLD = "\033[1m"
ITALIC = "\033[3m"
UNDERLINE = "\033[4m"
STRIKE = "\033[9m"
RESET = "\033[0m" # Reset to default style

def __str__(self):
return str(self.value)

0 comments on commit b160d33

Please sign in to comment.