-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Strip ANSI codes from page based on config - fixes #79 #86
Conversation
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.
Thanks, this is helpful! I have a few issues.
- What is the source for that regex? You should put it as a comment in the code
- Define the regex as a package/global variable like
ansiRegex
oransiRE
- Optionally strip ANSI in the
RenderANSI
function as well - Add the default value of
a-general.ansi
toconfig/config.go
, like all config options
You can add //nolint:lll
right before the regex variable to make linting pass, I don't mind in this case.
Thanks for the tips. I made your suggested changes. |
The Also I'd appreciate if you pointed to the source directly: // Source: https://github.com/acarl005/stripansi/blob/2749a054d4758fb0126d83aae590d7c9e8982d77/stripansi.go On another level, I wonder if there's any point in stripping non-color codes only sometimes. The way things are done currently, those codes will be displayed on the screen when ANSI is enabled, but stripped when it's disabled. It might make sense to only strip color codes, since the move and other codes don't actually affect the terminal display anyway, thanks to cview. A regex like |
Okay, that makes sense. I was thinking that the goal would be to strip all ansi codes, worrying that things like clear screen and move would potentially mess up the rendering of the page. I'll switch it to the simpler regex. |
Adds new boolean config option
ansi
in[a-general]
to switch whether ANSI codes in page content will be rendered to terminal.If
ansi
is set to false orcolor
is set to false, any ANSI codes will be stripped from fetched content.Fixes #79
Here is a summary of results for the various values of the two options:
Notice how it is not possible to have
ansi
color codes true andcolor
false at the same time. If thecolor
config option is false, it overrides the value ofansi
.Feature to only allow ansi codes in preformatted blocks is part of another issue (#59)