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

fmt hyperlinked CLI text #6177

Open
lionel-rowe opened this issue Nov 8, 2024 · 5 comments
Open

fmt hyperlinked CLI text #6177

lionel-rowe opened this issue Nov 8, 2024 · 5 comments

Comments

@lionel-rowe
Copy link
Contributor

lionel-rowe commented Nov 8, 2024

Is your feature request related to a problem? Please describe.

A function for creating hyperlinked text to print to CLI output (see Hyperlinks (a.k.a. HTML-like anchors) in terminal emulators).

Not sure whether this should go under fmt/colors or a new fmt/ansi. fmt/colors makes most sense to me given it already contains various formatting functionality that doesn't strictly relate to color.

Example:

console.log("\x1B]8;;https://deno.land\x07Deno dot land\x1B]8;;\x07")

^ prints in CLI console as Deno dot land.

Describe the solution you'd like

Something like this:

export function hyperlink(text: string, url: string | URL) {
    return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`
}

Describe alternatives you've considered

  • What should NO_COLOR output be? Maybe a markdown equivalent like [Deno dot land](https://deno.land)? Edit: or maybe not, this could easily break layouts. Probably best to just print the text without the hyperlink.
  • This feature isn't supported by all TTY environments — is there some way of feature detecting it? (Probably not). Per the gist linked above, all ECMA-48-compliant terminals that don't implement the feature simply fall back to showing the text with no hyperlink.
@lionel-rowe lionel-rowe changed the title @fmt hyperlinked CLI text fmt hyperlinked CLI text Nov 8, 2024
@kt3k
Copy link
Member

kt3k commented Nov 13, 2024

The support of that special sequence seems a bit too limited?

In spring 2017, GNOME Terminal and iTerm2 have changed this.

There seem no support on windows, and also default terminal of mac doesn't seem supporting?

@lionel-rowe
Copy link
Contributor Author

Windows Terminal supports it. Not sure about macos and don't have access to a mac device to find out.

@kt3k
Copy link
Member

kt3k commented Nov 14, 2024

Windows Terminal supports it.

👍

Not sure about macos and don't have access to a mac device to find out.

I tested with Terminal.app (the default one in mac), and it doesn't seem supporting it.

Screenshot 2024-11-14 at 12 35 01

On the other hand, I found that the builtin terminal of VSCode seems supporting it.

Screenshot 2024-11-14 at 12 36 12

Maybe Terminal.app is exceptional about the support of this..

@kt3k
Copy link
Member

kt3k commented Nov 14, 2024

Note: Warp doesn't support this. WezTerm and kitty do support this.

@kt3k
Copy link
Member

kt3k commented Nov 19, 2024

Another note: jetbrain editor's builtin terminal supports this

Looks like this is widely adopted except Warp and Terminal.app. However it is a little concerning that Terminal.app is the default of mac os..

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