jtdaugherty / vty-unix

Unix backend for Vty
Other
5 stars 4 forks source link

OSC-8 hyperlinks don't have any IDs set #7

Open dnkl opened 4 months ago

dnkl commented 4 months ago

Not sure if this should be reported here, or on the vty parent repo....

In any case, as far as I can tell, OSC-8 hyperlinks emitted by vty-unix does not set the URI ID. The ID is important, since it allows the terminal to match multiple URL (possibly disjoint) parts. See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#hover-underlining-and-the-id-parameter for details.

The specification mostly discusses an URL being split into multiple parts by either being line-wrapped across panes, or by being covered by "popups".

There's another issue though, and that's e.g. updating parts of an already printed URL, or opening/closing the OSC-8 hyperlink several times while printing an URL. One way to trigger this would be if the TUI "updates" part of an already existing URL.

From the terminal's perspective, starting a new OSC-8 sequence is the same as starting a new hyperlink; it may assign a completely different autogenerated ID than the last time. Even if the URL part of the sequence is the same (it's a bad idea to assign IDs by hashing the URL, since then multiple instances of the same URL will be treated as one and the same).

Depending on how the terminal renders OSC-8 hyperlinks, various visual glitches can happen:

Since it would be a bad idea for vty to auto-assign an ID (as mentioned above, you shouldn't base it on the URL itself), I believe the library (vty?) should expose an API to assign IDs to hyperlinks.

The application, which is the only entity that knows which hyperlink-cells belong to the same URL instance, can then assign an appropriate ID.

jtdaugherty commented 3 months ago

Thanks for this report, I did not know about the id thing at all!

Since it would be a bad idea for vty to auto-assign an ID (as mentioned above, you shouldn't base it on the URL itself), I believe the library (vty?) should expose an API to assign IDs to hyperlinks.

If I am understanding things right, then I think vty would be the best place to assign such IDs because 1) I definitely don't want to expose them to the application because the application developer won't want to care about this and won't even know how to assign the IDs, 2) it's fundamentally a concern of the terminal output protocol, not the application, and 3) the IDs can be generated from a sequence based on the renderer state in a way that I believe will get the right behavior without basing the content of the IDs on the URLs themselves, as you mentioned.

Now, while that would be my preferred way to deal with it, the practicalities are not immediately cut and dried to me. Any change to vty to deal with this will have an impact, at least for vty-unix and other platform packages if not also for brick and other vty-based software. I'll want to minimize that impact (i.e. breaking changes) as much as possible, so I'll need to give this some thought. At this point I can't promise that I will ultimately address this issue, although I understand the downside of the current implementation. (Although, as I understand it, it is largely a cosmetic downside, not a functional one.)

chhackett commented 3 months ago

FYI, if you decide to support this feature, I'm available to make any necessary changes to vty-windows.

jtdaugherty commented 3 months ago

Thank you, @chhackett!