go-ansi-parser
go-ansi-parser copied to clipboard
Hyperlink support
Right now, go-ansi-parser's ansi.Length
includes the URL part of a terminal hyperlink. This makes the line count super long even when it's visibly just a small piece of text.
ansi.Length
should ideally only return the visible text component of a hyperlink.
Example:
For string:
"\x1b[33;1mSource Code: \x1b[0m\x1b]8;;https://libdb.so/libdb.so\x1b\\diamondburned/libdb.so\x1b]8;;\x1b\\"
ansi.Length(str)
should return 35 (probably maybe?), but it currently returns 74.
The current workaround is to have a regex:
var ansiLinkRe = regexp.MustCompile(`(?m)\x1b]8;;([^\x1b]*)\x1b\\([^\x1b]*)\x1b]8;;\x1b\\`)
Then do line = ansiLinkRe.ReplaceAllString(line, "$2")
. This replaces the links away, and ansi.Length()
yields the correct number for the string (35).
Apologies for the delay in getting back to you. Do you have more information about "terminal links" as I'm not aware of them? My instinct is that as a library, it shouldn't try to derive any semantic meaning from the input, but I'm keen to understand more about this use case.
I can't find any standard page that I can link, but searching "OSC 8 Terminal" should give a bunch of results on hyperlink support in various terminals.
This looks great. Happy to accept a PR for this if you're willing to do it 👍