πŸ’Ύ Archived View for bbs.geminispace.org β€Ί s β€Ί Gemini β€Ί 1531 captured on 2023-12-28 at 16:51:25. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-11-14)

➑️ Next capture (2024-02-05)

🚧 View Differences

-=-=-=-=-=-=-

ANSI formatting

What do you think of the use of ANSI formatting (for colour and emphasis) in gemtext?

This is one of those cases where the current spec is silent. A tradition of using these escape sequences in certain circumstances has built up, popularised (and pioneered?) by Astrobotany, and later Wordo. It worked with some terminal clients just because they didn't think to strip the escape codes, and some graphical clients (Lagrange at least) then blessed the hack by specifically interpreting the codes. The informal convention that seems to have developed is that it's OK to use them, but you shouldn't expect clients to interpret them, and probably you should only present them to users who have specifically asked for them. On the other hand, one could say that it's a horrible hack which has no place in our lovely clean gemtext format.

So what do you think? Poll below. Personally, I'm torn between 3 and 4. Context for this question: I'm considering adding optional ANSI support to SGGS, but I'm not sure if I ought to promote this hack.

Wikipedia page on ANSI escape codes (we're talking specifically about the SGR section)

Astrobotony

Wordo

SGGS

Poll Results

1. ANSI formatting is neat and should be considered part of gemtext. Clients should support it.

β–ˆβ–ˆβ–ˆβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β– 13%

2. ANSI formatting is awkward but we don't need to ban it... servers can send it and clients may display it, but they shouldn't be expected to.

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–β–β–β–β–β–β–β–β–β–β–β– 50%

3. Like option 2, but it should only be tolerated within preformatted text; elsewhere clients SHOULD strip all ANSI escape codes.

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β– 21%

4. ANSI formatting is an abomination, and should be explicitly disallowed in the spec. Real gemtext does not contain any such escape codes, and clients should of course strip any they find.

β–ˆβ–ˆβ–ˆβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β– 13%

5. Other, see comment.

β–ˆβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β– 3%

38 votes were cast.

πŸ—³οΈ

Posted in: s/Gemini

πŸš€ mbays

Jun 04 Β· 7 months ago Β· πŸ‘ Addison Β· πŸ€” 1

19 Comments ↓

πŸš€ skyjake Β· 2023-06-04 at 10:00:

I think allowing ANSI codes in preformatted blocks and banning them elsewhere is a nice compromise. After all, ANSI codes are one way of preformatting the text.

No client should be expected to support the codes because 1) that's a lot of work, and 2) not all codes are even applicable everywhere, so stripping them should be the recommended behavior if the client doesn't handle them.

πŸš€ skyjake Β· 2023-06-04 at 10:03:

@mbays (This post could be moved to s/Gemini?)

πŸš€ mbays Β· 2023-06-04 at 10:07:

@skyjake Oops yes, I meant to put it in /s/gemini... thanks for letting posts be moved to subspaces after posting!

πŸš€ mbays Β· 2023-06-04 at 10:32:

@skyjake Yes, I think there's an argument for accepting that the tradition of ANSI text art is established enough that it can be part of gemtext. Quick thoughts on how this might be specced: outside preformatted, escape codes are illegal so there's no need to spec what clients should do with them (e.g. they could just strip the escape char, leading to something unreadable, and that's fine). Within preformatted, only SGR codes (\\e[...m) are permitted. Clients should expect them, but can do what they want with them, including just stripping them. Possibly we'd want to indicate which ones clients might consider supporting -- maybe just 0 (reset), the display variants 1,2,3,4,7,9 and their negations, and the colour codes 30-49 in their various forms. Or maybe something stricter (0,1,3,4,30-37,40-47?) to have something minimal which clients who support it at all can be expected to support.

β˜•οΈ mozz Β· 2023-06-04 at 13:30:

popularised (and pioneered?) by Astrobotany, and later Wordo.

Konpeito did it first (to add color to the cassette logo), and then later made them optional, and then later removed them completely IIRC.

What other capsules are even using colors? I think I've seen them maybe a half-dozen times in total. It's such a pain to style text this way that it only really makes sense for CGI scripts and other dynamically generated content. Or, very artsy capsules where the author is explicitly pushing the limits of the gemtext format.

πŸ¦€ jeang3nie Β· 2023-06-04 at 17:16:

I always liked the aspect of Gemtext that styling is left entirely to the client, putting the burden on authors to come up with something worth reading. Well, moreso than on the web, anyway. When ansi codes started appearing or seemed like a conscious effort to find a loophole around that constraint. I'm not any more in favor of it than I am people misusing unoccupied characters for stylistic effect.

That said, compromise is a part of life. And I can see two major uses for escape codes, ansi art, which already is a big part of Gemini, and preformatted code blocks since so many of us here are big Unix nerds. That's something I'd be tempted to add to my capsule.

πŸš€ mbays Β· 2023-06-04 at 17:20:

@jeang3nie That's a good point about syntax highlighting code blocks -- I think that's better than abusing the alttext line to indicate the language so the client can do highlighting, as has been suggested.

🐝 Addison · 2023-06-04 at 18:38:

Rosy Crow converts everything to HTML/CSS under the hood, so this shouldn't be too difficult to implement. Now I have another excuse to procrastinate on adding Titan support. 😁

πŸ¦€ jeang3nie Β· 2023-06-04 at 20:33:

@mbays it's one of the few things that I miss from blogging on the big web using Markdown. What I find interesting is that the alt text a we know it in Gemtext is used for precisely that in CommonMark - relaying to the renderer that this block should be rendered as code. I agree that this shouldn't be done in Gemtext though, because that bit of info should be reserved for those using screen readers with ansi art.

I'm not even sure it's something that I'll ever get around to implementing, but it has been in the back of my brain for a long time. I have some idea how I could automate adding all of those escapes when building the capsule already, just too many projects going at once.

πŸ‘€ emilis Β· 2023-06-04 at 20:49:

The colours you added to the word β€œcolour” made it hard to read, therefore I would like for my browser to strip them.

I’m not sure about syntax highlighting case too, because the author can’t control the background that a browser/terminal is providing. It is hard to find colors that work on both light and dark backgrounds and most authors falsely assume everyone is using their mode of choice. I notice this quite often, because I use a light terminal background.

πŸ¦‹ teal Β· 2023-06-05 at 11:48:

I want to be able to use it in some of my notes, but I haven't been able to get it to display in amfora.

πŸ›°οΈ lufte Β· 2023-06-05 at 15:42:

I don't like it. I don't think it should be banned because then we would have to explicitely ban countless formats being thrown in preformatted blocks but I don't think clients should be forced to process them. It breaks accesibility and my choice of having any background color I like.

πŸš€ mbays Β· 2023-06-05 at 17:36:

@emilis @lufte re background colour: a terminal client could be more clever about how it renders ANSI-coloured text than just passing the escape codes through to the terminal, it could munge them to account for a configured background colour. @lufte: Banning it (prohibiting it in the spec) would be straightforward, and I don't think there's any slippery slope there. It's certainly the cleanest option. I'm surprised there isn't more support for it in the poll...

πŸ›°οΈ lufte Β· 2023-06-05 at 18:36:

@mbays I think I understood option 4 as "Ban capsule owners from writing special codes in their document" instead of "force clients to not do any special handling with the text in pre blocks", which makes more sense. In that case I'm all for option 4.

πŸš€ skyjake Β· 2023-06-05 at 20:36:

@mbays I agree it's SGR that makes most sense here, but I think because actually adding support for these codes is highly implementation dependent (for instance, can be much easier for a TUI app), there should be no common baseline of expected support. The only common denominator should be that clients strip out the sequences, if they can't parse and apply them properly.

But IMO even that is too complicated a requirement for implementing a Gemtext parser. My speccing suggestion is to simply not pass control characters like <ESC> through to disable these sequences, even when the client just dumps the source to a terminal.

Allowing SGR in preformatted blocks makes some sense because there one might reasonably expect a client to take the part of the source between the ``` markers and show it as-is (inside a terminal emulator).

The way GUI clients would render the codes depends greatly on the underlying display method. A web view has powerful CSS styling features, so once you parse the sequence, you can display it easily. Other GUI controls might be more limited in what they can render. In any case, the client would have to be smart about the presentation, by choosing colors and fonts that remain legible.

It's all a surprising amount of complexity when implemented properly, however I think it's still compatible with the idea that the client is empowered to present the Gemtext source as it sees fit.

❄ freezr Β· 2023-06-05 at 23:41:

I believed this topic was already settled down, and we eventually agreed it was a bad idea especially because text-readers read the full text...

πŸš€ mbays Β· 2023-06-06 at 23:01:

@skyjake Right yes, it's best to have the baseline behaviour lead to something unreadable when escape sequences are used, discouraging their use except in dynamic systems where the user has specifically opted in to receiving them.

That doesn't mean we can just leave optional use of escape sequences unspecced and let conventions around them build up, because that's a definite loophole for extending the capabilities of gemini. So I think we have to tightly constrain what's permitted. Hopefully Solderpunk will pronounce on it one day.

πŸš€ totroptof Β· 2023-06-25 at 01:17:

There is a π˜₯𝘦 𝘧𝘒𝘀𝘡𝘰 standard ANSI sequence that provides a little bit more utility than SGR: VTE ([and a bunch of other terminals]) support inline hyperlinks with OSC 8. There’s a [rough spec] available as a Github Gist. I’m not sure how widely used it is, but I have noticed GCC using it to link to documentation about warnings (for example).

I’m not really advocating that ANSI sequences in general and OSC 8 in particular be widely adopted so we can have inline links, I just thought I would mention it because it’s kinda neat (and it tickles that β€œhow can I exploit this to do something interesting” itch πŸ™‚).

β€” and a bunch of other terminals

β€” rough spec

πŸš€ mbays Β· 2023-06-25 at 07:50:

@totroptof Oof... thanks. That's a serious extensibility hole which I wasn't aware of at all. OK, so this is a great argument for making sure terminal gemini clients strip out most (at least all non-CSI) escape sequences, and for having the spec tightly constrain which, if any, sequences may not be stripped.

By the way, after the discussion in this thread, I tweaked how my terminal client diohsc handles this: as of the next version, escape characters in gemtext are filtered out except where they introduce CSI sequences ('[') within a preformatted block.