-
Couldn't load subscription status.
- Fork 7.3k
Enabling custom color themes with the GLAMOUR_STYLE environment variable
#1411
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
Conversation
| } | ||
|
|
||
| func RenderMarkdown(text string) (string, error) { | ||
| style := "notty" |
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.
With this removal, we lose the feature that, when color is disabled, no coloring styles should take place. I think that notty is important to keep unless the output is to a terminal (or color was otherwise forced)
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.
Agreed. Will put back.
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.
Once the underlying issue in Glamour is resolved, I think the new implementation I just pushed should be acceptable for notty functionality.
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.
Fixed.
utils/utils.go
Outdated
|
|
||
| tr, err := glamour.NewTermRenderer( | ||
| glamour.WithStandardStyle(style), | ||
| glamour.WithEnvironmentConfig(), |
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.
Apart from losing notty support, the switch to WithEnvironmentConfig opens us back to charmbracelet/glamour#72 right after we fixed it in #1402.
What do you think about this logic instead:
- if color is disabled:
WithStandardStyle("notty") - if GLAMOUR_STYLE is set to a simple string (no slashes):
WithStandardStyle(os.Getenv("GLAMOUR_STYLE")) - if GLAMOUR_STYLE looks like a path (e.g. has slashes):
WithStylePath(os.Getenv("GLAMOUR_STYLE"))
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 think I'd rather fix the root problem in Glamour than pollute your code base with temporary workarounds. Lemme make a PR to fix Glamour. Looks simple enough.
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.
PR made: charmbracelet/glamour#73
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.
PR merged.
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.
Sure, it would be great it glamour fixed this upstream!
However, I'm not sure why we would wait for the upstream fix if Glamour gives us enough APIs to work around the issue anyway.
If you're keen on waiting for the upstream fix to get merged, then let us know when that happens 🙏
| // glamour.WithBaseURL(""), // TODO: make configurable | ||
| // glamour.WithWordWrap(80), // TODO: make configurable |
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 feel that it was more clear how to exactly make BaseURL and WordWrap configurable with the old instructions rather than with the new ones. Could we go back to using more verbose syntax?
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.
Yeah. I went with the current syntax because it seemed cleaner with the if blocks, but I guess it would be better to do it the previous way to get the increase in functionality later down the road when the TODOs are actually implemented.
|
I'll give it a day or two to see if my Glamour PR gets merged so I don't waste effort implementing a fix here just to tear it out once the fix is merged in. |
|
@mislav Got the fix implemented and merged into Glamour. |
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.
Fantastic! Thank you for the feature and for the upstream fix 🎉
|
Bonjour le monde |
The Glamour library that GitHub CLI uses to render Markdown recently added support for a
GLAMOUR_STYLEenvironment variable. This variable allows users to set a persistent color theme config.This PR utilizes the new
glamour.WithEnvironmentConfig()function (which defaults toautoifGLAMOUR_STYLEis not set) to enable custom themes in the GitHub CLI.The way this PR is currently written sets the default rendering style to
autoinstead ofnotty. If there are objections I can take a stab at a minor refactor.