-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add --force-color flag to zed validate #435
Conversation
internal/cmd/validate.go
Outdated
setForceColor := cobrautil.MustGetBool(cmd, "force-color") | ||
if setForceColor { | ||
lipgloss.SetColorProfile(termenv.ANSI256) | ||
fmt.Println(lipgloss.DefaultRenderer().ColorProfile() == termenv.ANSI256) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the need to print here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 🤦
traceStyle = lipgloss.NewStyle().Bold(true) | ||
// NOTE: these need to be set *after* the renderer has been set, otherwise | ||
// the forceColor setting can't work, hence the thunking. | ||
success = func() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the cost of initializing this each time? alternatively, these could be left as uninitialized vars, and initialize them after we've checked the flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but that spreads the definitions around the file, and some of the definitions are used by multiple functions. I don't think it's particularly expensive, though that isn't because I've profiled it.
Fixes #434
Description
See #434. There are non-terminal environments (e.g. some CI environments) that support color, but
lipgloss
assumes that a non-terminal environment is uncolored. This provides a--force-color
flag that allows the user to override this behavior and get color output forzed validate
, which is the only place we're usinglipgloss
.Changes
PreRunE
that interprets the flagDefaultRenderer
Testing
Review. See that things are green. The way that I was able to test this locally was comparing:
Where the command is run from a folder that has a built
zed
binary.