cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open Praveen005 opened this issue 1 year ago • 2 comments

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

Praveen005 avatar Jun 23 '24 18:06 Praveen005

@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

haardikdharma10 avatar Jun 25 '24 23:06 haardikdharma10

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

Praveen005 avatar Jun 26 '24 14:06 Praveen005