Skip to content

Only support ANSI codes in preformatted blocks #59

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

Closed
makew0rld opened this issue Jul 31, 2020 · 3 comments
Closed

Only support ANSI codes in preformatted blocks #59

makew0rld opened this issue Jul 31, 2020 · 3 comments
Labels
bug Something isn't working question Further information is requested UI Deals with the visual user interface
Milestone

Comments

@makew0rld
Copy link
Owner

No description provided.

@makew0rld makew0rld added the bug Something isn't working label Jul 31, 2020
@makew0rld makew0rld added this to the v1.5.0 milestone Aug 3, 2020
@makew0rld makew0rld added help wanted Extra attention is needed question Further information is requested labels Aug 28, 2020
@sumpygump
Copy link
Contributor

I researched this and discovered what is going on. The gist is the ANSI codes are being reset for each line.

In renderer.go, all the highlight region definitions like "[" + config.GetColorString("regular_text") + "]" and [-::-] and [-] are embedded on every line, so if you set a color in the gmi content with an ANSI code, it will not keep the color to the next line(s). It works in the case where the ANSI code is on the same line as the gmi content. This is because the renderer will apply the regular_text color for example first and then the ANSI code in the line's content will be applied and then finally at the end of the line the renderer will reset the color. Even when a long line is wrapped, each wrapped line will be reset too.

The following snippet is an example that illustrates the above description. Note, of course to test it out on a real page, you must convert the ^[ to the escape character, but I have supplied a screenshot from Amfora below it:

^[[94m Setting the color on the same line works ^[[0m
^[[94m 
But trying to set the color from the previous line doesn't work because it gets reset.

^[[94m But what if it is a really long line like this one? When it renders the wrap, each new line gets a color reset. lorem ipsum lorem ipsum lorem ipsum lorem ipsum  lorem ippsum lorem ipsum lorem ipsum lorem ipsum  lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum  lorem ipsum lorem ipsum lorem ipsum llorem ipsum  lorem ipsum lorem ipsum lorem ipsum lorem ipsum  lorem ipsum lorem ipsum lorem ipsum lorem ipsum  lorem ipsum lorem ipsum lorem ipsum lorem ipsum  lorem ipsum loreem ipsum lorem ipsum lorem ipsum.

Even a link could have some ANSI color codes in the middle of it (the word
middle is in yellow), but unfortunately a op() (0m) to reset the color changes
off the default for the link.

=> gemini://link What if a color code is the ^[[93mmiddle^[[0m of a link text?

image

For the makeworld.gq banner, it could be fixed in the content by adding the ^[[94m escape code at the beginning of each line of the ascii art. In general, I am not sure what a long-term solution for supporting ANSI color codes in page content would be.

If the user config has color = false then all the ANSI codes in any rendered page content will be output as raw characters and not look good. Perhaps a solution to that is to strip out the codes if the config has color=false ?

Also, if users have defined color overrides, for example regular_text or bg then things get wonky with ANSI color codes in the content, depending on the colors are and how they are reset (or not) in the middle of the line.

@makew0rld makew0rld removed this from the v1.5.0 milestone Aug 29, 2020
@makew0rld
Copy link
Owner Author

makew0rld commented Aug 29, 2020

Thank you for discovering what was causing this bug, it seems obvious now :)

For the makeworld.gq banner, it could be fixed in the content by adding the ^[[94m escape code at the beginning of each line of the ascii art. In general, I am not sure what a long-term solution for supporting ANSI color codes in page content would be.

Doesn't make much sense for ANSI art to have to change to support my client, so I definitely want to figure out that long term solution.

As for the changing colors in the link text, I'm pretty opposed to that. I don't like the idea of ANSI codes being able to affect user-defined colors for special gemtext lines.

Maybe an overall solution could be this:

  • Only support ANSI codes in preformatted blocks on text/gemini
  • If the preformatted block contains ANSI codes, set the text to white at the beginning and the background to black, and let the ANSI codes do their thing
  • Otherwise, apply the user's color for "preformatted_text", and the general background

Also:

  • Override user's theme to set white text and black background on ANSI documents (text/x-ansi)

If the user config has color = false then all the ANSI codes in any rendered page content will be output as raw characters and not look good. Perhaps a solution to that is to strip out the codes if the config has color=false ?

I've spun this up into a new issue, thanks for the suggestion. See #79.

@makew0rld makew0rld removed the help wanted Extra attention is needed label Aug 29, 2020
@makew0rld makew0rld changed the title ANSI colors on makeworld.gq don't display properly Only support ANSI codes in preformatted blocks Aug 29, 2020
@makew0rld makew0rld added the UI Deals with the visual user interface label Aug 29, 2020
@makew0rld makew0rld added this to the v1.6.0 milestone Oct 1, 2020
@makew0rld
Copy link
Owner Author

Support for ANSI color codes in preformatted blocks was added in 819023d and will be in v1.6.0. The suggestions I made earlier about changing the user's themed background and text colour were not applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested UI Deals with the visual user interface
Projects
None yet
Development

No branches or pull requests

2 participants