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

chore: Improve Tool's Output for Better User Visibility and unify CLI output library #284

Closed

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Sep 28, 2023

Description

Ensuring that users can swiftly identify critical warnings and errors is important for a smooth user experience. This PR focuses on making these critical messages stand out amidst the standard output of our tool. Specifically, the changes introduced are:

  • Unify CLI Output Library: To provide a consistent output experience across all messages. (see that has places we are using fmt.Println others logrus which are not in debug mode and by last other, we are using the colour.faith )
  • Color-coded Messages:
    • Errors are now highlighted in red, making them immediately noticeable.
    • Warnings are displayed in yellow, ensuring they are distinguishable from regular logs and errors.

Example:

Screenshot 2023-10-02 at 13 28 55

@camilamacedo86 camilamacedo86 force-pushed the use-logrus-tty branch 2 times, most recently from f5288bd to 7ff21ee Compare September 28, 2023 12:57
@doanac
Copy link
Member

doanac commented Sep 28, 2023

I think using a logger for a CLI user interface is a little unusual. I believe the more common approach is abstracting code that prints stuff into some type of project "formatter" where the Print type function gets some context to help know about coloring.

@camilamacedo86
Copy link
Contributor Author

Hey @doanac! 😊

I think using a logger for a CLI user interface is a little unusual. I believe the more common approach is abstracting code that prints stuff into some type of project "formatter" where the Print type function gets some context to help know about coloring.

Ah, you got a point! We've got logrus in the mix already, so I figured, why not stick to the beat?

But hey, I’m totally vibing with the fmt.Print idea. It’s neat and cuts down on the extra baggage – cool beans! I’ll spin that record and make the tweaks when I catch a free moment.

Thanks a bunch! 🚀

@camilamacedo86 camilamacedo86 changed the title Use logrus to enhance visibility and user experience WIP : Use logrus to enhance visibility and user experience Sep 28, 2023
subcommands/common_config.go Outdated Show resolved Hide resolved
subcommands/targets/edit.go Outdated Show resolved Hide resolved
subcommands/targets/offline-update.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
subcommands/common.go Outdated Show resolved Hide resolved
@camilamacedo86
Copy link
Contributor Author

Hi @vkhoroz, @doanac,

Firstly, thank you for your valuable insights regarding this small suggestion.

Regarding the use of println with ANSI colors:

Using fmt.Println("\033[31mERROR:", "Your message", "\033[0m") might not deliver as expected. In terminals that don't support ANSI sequences (which seem prevalent in older Unix and Windows versions), the output won't display colors and will instead appear as \033[31mERROR message\033[0m.

On the other hand, logrus appears to be adept at navigating these scenarios, opting to simply output ERRO in incompatible terminals.

The driving force behind this proposal was to enact a low-effort/good first issue that could provide tangible value to our users. With the volume of notifications we produce, errors and warnings could easily go unnoticed. Given our ongoing use of logrus, it felt like a logical step to further embed it, ensuring greater code consistency.

However, if logrus doesn't align with the team's vision, especially when weighing the challenges associated with fmt.Println and ANSI, it seems wise to reassess this one.

For now, I'll be closing this. However, if you have alternative strategies in mind or believe there's a more effective approach worth exploring, please don't hesitate to reach out. I'm always here to assist and collaborate

@camilamacedo86
Copy link
Contributor Author

camilamacedo86 commented Oct 2, 2023

Hi @doanac and @vkhoroz :

I've revisited this issue and observed that we're also utilizing the "github.com/fatih/color" package in certain areas. Given that we're already leveraging this package elsewhere, can we consider employing it for displaying errors in red and warnings in yellow? It would be beneficial to maintain consistent behavior across the tool. What are your thoughts on this?

See:

color.Green(line)
} else if line[0] == '-' {
color.Red(line)
} else {
fmt.Println(line)

@camilamacedo86 camilamacedo86 changed the title WIP : Use logrus to enhance visibility and user experience chore: unify CLI output library; use yellow for warnings, red for errors Oct 2, 2023
@camilamacedo86 camilamacedo86 changed the title chore: unify CLI output library; use yellow for warnings, red for errors chore: Improve Tool's Output for Better User Visibility and unify CLI output library Oct 2, 2023
@vkhoroz
Copy link
Member

vkhoroz commented Oct 2, 2023

@camilamacedo86 let's table this, please.

I know that this change was done by some sort of find magic -exec sed magic, so it was probably easy.
But, TBH I don't like the final result.

If I were a user, I'd like only the ERROR part to be in red, and the message itself not so fancy.
This also means, that as a developer I'd want all these messages to be refactored to use subcommands.DieNotNil where applicable.

But, I feel like I'm starting a discussion by this sentence; and I don't want a new round of debates.
We have more important tasks to spend our effort.

@vkhoroz vkhoroz closed this Oct 2, 2023
@camilamacedo86 camilamacedo86 deleted the use-logrus-tty branch October 2, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants