Add OSC 8 support#2243
Conversation
There was a problem hiding this comment.
Nice, I just tested the following lfrc file and it works:
echo "\033]8;;https://example.com\033\\example.com\033]8;;\033\\"About your comments:
- I don't like that
stripAnsiworks on bothCSIandOSCwhileapplyAnsiCodesonly works onCSI. That could lead to confusion.
I think the functions can be renamed:
stripAnsi->stripTermSequenceapplyAnsiCodes->applySGR
- Is there any point in having
parseEscapeSequence?
I guess this is now basically just applyTermSequence except that the base style is the default style. Generally terminal sequences like this modify an existing style, not create a new one. It should be fine to remove parseEscapeSequence and just use applyTermSequence only.
- What about the
C1versions mentioned in here?
It's probably fine to leave it for now, processing terminal sequences can be a pain to deal with for ones that are not so standardized. I'm not even sure how necessary it is to handle BEL either, but I'm not too fussed either way.
One other thing - I understand this is just a draft for now, but you should add unit tests for this later on.
|
I also tested this feature and noticed that the current implementation does not preserve params in hyperlinks. In particular, the id parameter is important so that terminals can highlight all hyperlinks with the same id. You can try this in Bash and see how your terminal highlights them together: There's also a quirk in the feature that highlights words when the mouse is over a word, and spaces when the mouse is over them. It gives the impression that there are two hyperlinks instead of one: This can be replicated with Alacritty, Contour and Xfce terminals, but not with Kitty and Wezterm. Despite these issues, this looks very promising! |
|
Hey @veltza! Thank you so much for testing this out and leaving some feedback! For testing, I mostly use this example file. I noticed that even outside I found it rather difficult to differentiate between mismatches caused by incorrect parsing on my side and different implementations on a terminal level. However, I will look deeper into this. Edit: I noticed you were also involved in testing the new |
I also used that test file when I implemented OSC-8 support in my st fork. The file includes so many edge cases that I didn’t bother handling all of them either. So I recommend that you don't spend too much time on them either, because applications use fairly simple hyperlinks anyway. |
This is fixed now!
OK, this is related to the Edit: This has been fixed now as well. |
joelim-work
left a comment
There was a problem hiding this comment.
I have looked over the code and it's generally fine, some minor suggestions from me.
This reverts commit 3d4452f.
|
Please take one last look, @joelim-work. |
|
@CatsDeservePets Hold on, I’ve found a bug. I’ll report it shortly. |
There was a problem hiding this comment.
I also analyzed the strange behavior of hyperlinks using my st fork and found that lf generates two hyperlinks from a single hyperlink and draws them on top of each other.
For example, if I print a hyperlink like this:
printf '\e]8;;http://example.com\e\\This is link\e]8;;\e\\\n'
lf generates two hyperlinks:
- First, it prints the hyperlink as it should:
printf '\e[3;53H\e]8;;http://example.com\e\\This is link\e[3;105H\e[0m\e]8;;\e\\\n'
- But then for some reason it prints another hyperlink on top of it and only renders the words in the link text because it skips spaces using escape sequences:
printf '\e[3;53H\e]8;;http://example.com\e\\This\e[3;58His\e[3;61Hlink\e[3;105H\e[0m\e]8;;\e\\\n'
This second hyperlink is what's causing the strange behavior. So if we could get rid of it, we wouldn't need to create any fallback ids in the first place.
Oh, interesting. |
Indeed. It would be interesting to know what causes it and why. My concern is that, without knowing its purpose, it might cause additional side effects. Edit: I found out that the behavior comes from tcell and can be reproduced with the hyperlink.go demo. I also found out that it was gdamore/tcell@d17cf8b that broke the behavior of hyperlinks. But since I am not familiar with tcell, I don't understand why it causes this regression. So I guess no one uses hyperlinks because no one has noticed this yet. |
And once again thank you for your research. So this is outside the scope of this PR. I will update the custom It seems to me that there might be a problem with |
|
Regarding the |
Without the id, it's up to the terminal emulator to decide which links belong together (some are smarter than others). I do agree, ideally the ID is provided by the external application, but that isn't always the case (I'd imagine users writing some configuration to output clickable links don't add it either). Quoting from there:
|
@joelim-work The reason has already been explained in this thread. So feel free to fix |
|
I think at this point, this PR can be merged. |
|
Sorry, I was busy the last few days so I didn't have a chance to respond. Regarding the double hyperlink issue in Tcell, I can reproduce it with the But this is just speculation on my part, it's probably worth raising an issue in Tcell since it would be nice to not have this kind of workaround. The code is fine for now though, thanks for working on the feature. |
Given @joelim-work's requirements:
Some thoughts:
stripAnsiworks on bothCSIandOSCwhileapplyAnsiCodesonly works onCSI. That could lead to confusion.parseEscapeSequence?C1versions mentioned in here?