Skip to content
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

Hyperlink support #6

Open
diamondburned opened this issue Mar 19, 2023 · 4 comments
Open

Hyperlink support #6

diamondburned opened this issue Mar 19, 2023 · 4 comments

Comments

@diamondburned
Copy link

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.

@diamondburned
Copy link
Author

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).

@leaanthony
Copy link
Owner

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.

@diamondburned
Copy link
Author

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.

@leaanthony
Copy link
Owner

This looks great. Happy to accept a PR for this if you're willing to do it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants