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

fix(templatehelper): no styles in Ascii mode #14

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

justenwalker
Copy link
Contributor

@justenwalker justenwalker commented Jul 24, 2020

If the color profile doesn't support ANSI color codes, then it likely shouldn't support any Style options either. This returns a no-op funcmap from termenv.TemplateFuncs when the color profile is Ascii.

@justenwalker
Copy link
Contributor Author

justenwalker commented Jul 24, 2020

If the terminal doesn't support colors, also it doesn't support styles like Bold, Cross-out, etc.

I'm actually not sure this is the case, but I'm not aware of terminals which do support text style options that don't also support colors. And also, from the principle of least surprise -- I'd expect if my color profile is Ascii, I shouldn't be getting any ANSI escape codes in the output. (ie: my output is going to a file, not the terminal)

If the color profile doesn't support ANSI color codes, then it likely
shouldn't support any Style options either. This returns a no-op funcmap from
termenv.TemplateFuncs when the color profile is Ascii.
Comment on lines +38 to +40
if !bytes.Equal(buf.Bytes(), expected) {
t.Fatalf("template output does not match golden file.\n--- Expected ---\n%s\n--- Actual ---\n%s\n", string(expected), string(actual))
}
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'm not the biggest fan of doing this kind of comparison and output in tests, but I didn't want to introduce a test-only dependency unless you're ok with it.

A couple I had in mind to make these sorts of tests more readable/maintainable:

Copy link
Owner

Choose a reason for hiding this comment

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

I agree, that's probably a sensible suggestion. I haven't looked into goldie yet, but I've used testify before.

@mszostok
Copy link

mszostok commented Aug 3, 2022

Hi,

First, really cool library 🚀

I wanted to use it and I ran into the same issue today. @muesli are you OK with this change? Do you consider merging it soon?

It is just a helper function, so I just introduce my own. However, it would be to use built-in one ;)

@muesli
Copy link
Owner

muesli commented Sep 22, 2022

I'm not opposed to the change, it's the right thing to do. I didn't merge it so far, because it was consistent with the actual behavior of termenv's core API. That was always a design issue however and never the intended behavior. Recent API changes (termenv.Output) rectified this situation and as such I'm leaning towards (finally!) merging this PR.

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