Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jessemillar
Copy link
Contributor

@jessemillar jessemillar commented Jul 23, 2020

The Glamour library that GitHub CLI uses to render Markdown recently added support for a GLAMOUR_STYLE environment variable. This variable allows users to set a persistent color theme config.

This PR utilizes the new glamour.WithEnvironmentConfig() function (which defaults to auto if GLAMOUR_STYLE is not set) to enable custom themes in the GitHub CLI.

The way this PR is currently written sets the default rendering style to auto instead of notty. If there are objections I can take a stab at a minor refactor.

}

func RenderMarkdown(text string) (string, error) {
style := "notty"
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will put back.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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(),
Copy link
Contributor

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"))

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR merged.

Copy link
Contributor

@mislav mislav left a 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 🙏

Comment on lines 37 to 39
// glamour.WithBaseURL(""), // TODO: make configurable
// glamour.WithWordWrap(80), // TODO: make configurable
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@jessemillar
Copy link
Contributor Author

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.

@jessemillar
Copy link
Contributor Author

@mislav Got the fix implemented and merged into Glamour.

Copy link
Contributor

@mislav mislav left a 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 🎉

@mislav mislav merged commit 58bd549 into cli:trunk Jul 28, 2020
@dbalde
Copy link

dbalde commented Sep 5, 2020

Bonjour le monde

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