civo / cli

Our Command Line Interface (CLI) for interacting with your Civo resources
Apache License 2.0
171 stars 82 forks source link

Suggestion: Use ANSI Escape Codes Instead of Third-Party Library for Console Colors #432

Open Praveen005 opened 2 weeks ago

Praveen005 commented 2 weeks ago

Background:

Currently, the CLI uses the github.com/gookit/color library to handle colored output in the console. While this library does its job well, it introduces an additional dependency that might not be necessary.

Suggestion:

I propose replacing the github.com/gookit/color library with ANSI escape codes for coloring text in utility/color_util.go

Here is how the current functions could be rewritten using ANSI escape codes:

color_util.go

haardikdharma10 commented 2 weeks ago

@Praveen005 can you provide an example (possibly a screenshot) of the preview of any existing command by using the color_util.go you provided above

Praveen005 commented 2 weeks ago

This is the output with ANSI Codes:

Screenshot 2024-06-26 190625

This is with the present code:

Screenshot 2024-06-26 191353

You would have also noticed that, the first Error is not colored, and the reason is because, It is being directly printed using fmt.Printf()

Likely reason for doing this might be because when we import utility package in config, it leads to circular import.

Screenshot 2024-06-26 192044

But there is a workaround for isolated cases, we can directly use the ANSI code for Red in the string itself, like:

Screenshot 2024-06-26 193410

Result:

Screenshot 2024-06-26 193437