denoland / denoland/std

fmt hyperlinked CLI text

Open
#6,177 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**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_](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)).

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:

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

^ prints in CLI console as [Deno dot land](https://deno.land).

**Describe the solution you'd like**

Something like this:

```ts
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.