-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Conversation
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) |
2ec4253
to
a8fb303
Compare
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.
a8fb303
to
7bf6236
Compare
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)) | ||
} |
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'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:
- https://github.com/sebdah/goldie for managing golden files (you can run the test with -update to update the files from the code output)
- https://github.com/stretchr/testify has test assertions with useful textual diffs.
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 agree, that's probably a sensible suggestion. I haven't looked into goldie
yet, but I've used testify
before.
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 ;) |
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 ( |
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 isAscii
.