Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coloured CLI output #4

Open
Qwerty-133 opened this issue Jun 24, 2023 · 7 comments
Open

Coloured CLI output #4

Qwerty-133 opened this issue Jun 24, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Qwerty-133
Copy link
Owner

spcache doesn't use any colours right now, click.secho can be used to print coloured text for important text.

https://github.com/ewels/rich-click can be looked into for pretty help outputs, however there will be some added overhead of importing rich.

There should however be a way to use callbacks for --help and then delegate to rich-click, so rich-click doesn't need to be imported unless the user uses the --help option

@Qwerty-133 Qwerty-133 added enhancement New feature or request good first issue Good for newcomers labels Jun 24, 2023
@faisalalisayyed
Copy link

I hope this communication finds you in good health. I'm writing to inquire about the spcache project and the outstanding issue "Adding Coloured Text to --help Option." I am passionate about this topic and would like to contribute to the project by assisting with its implementation.
As you mentioned, use the "rich-click" module to generate coloured text outputs, specifically for the --help option. I will import the library only when absolutely necessary, minimising potential overhead and optimising performance.
Please assign this issue to me. I am excited to contribute to the project and will provide progress updates on a regular basis throughout the development process. I am devoted to working together.

@Qwerty-133
Copy link
Owner Author

Hello, rich-click is a secondary goal. You could make a PR for simple coloured text first
We shouldn't go overboard with the colours, success messages in green, warnings in yellow, and errors in red is pretty much all we need.

@faisalalisayyed
Copy link

@Qwerty-133 I was browsing over the rich-click documentation, and it states to use import rich_click as click. After doing this, the help prompt looks excellent, and the spcache works properly after the import. Should I create the PR using rich-click or just skip and go for simple coloured text as you ask
demo

@Qwerty-133
Copy link
Owner Author

See ewels/rich-click#114
We'll have to change the way we're raising exceptions, you could use classes in this way:

import rich_click as click
class ExceptionBase(click.ClickException):
    """
    Base class for exceptions raised by this CLI tool.

    Supports reading the message from a class variable.
    """

    exit_code: t.ClassVar[int]
    message: t.ClassVar[str]

    def __init__(self) -> None:
        super().__init__(self.message)

class FileDetectionError(ExceptionBase):
    """Raised when the Spotify prefs file can't be auto-detected."""

    exit_code = 2
    message = (
        "The Spotify prefs file couldn't be auto-detected."
        "\nPlease specify a path to the prefs file using the --file option."
    )


def handle_file(
    ctx: click.Context, file: t.Optional["dotenv.main.StrPath"], no_prompts: bool
) -> "dotenv.main.StrPath":
    if file is None:
        from spcache import detect

        file = detect.detect_prefs_file()
        if file is None:
            raise FileDetectionError
...

@Qwerty-133
Copy link
Owner Author

Hey @C0DE-SLAYER, could you provide an update on the status of this PR? Thanks!

@faisalalisayyed
Copy link

Hey @Qwerty-133 if you would mind can you explain me what i have to do for now i will make a pull request for the early request of your which was "We shouldn't go overboard with the colours, success messages in green, warnings in yellow, and errors in red is pretty much all we need." and looking forward for the rich_click implementation is that good. Thanks!

@faisalalisayyed
Copy link

@Qwerty-133 I have open a pull request check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants