EDIT: See sindresorhus/terminal-link
function hyperlink(text, url, attrs) {
return `\u001b]8;${attrs || ''};${url || text}\u0007${text}\u001b]8;;\u0007`;
}
console.log(
`See issue ${
hyperlink('#319 on GitHub', 'https://github.com/chalk/chalk/issues/319')
}`
);
For more info see Hyperlinks (a.k.a. HTML-like anchors) in terminal emulators
Detection for this is a nightmare, even moreso than truecolor...
I just want open discussion about this awesome feature.
Especially about fallback API when colors are not supported.
I have suggestion about third argument which may be:
true — write text followed by URL in parenthesis: text(url)false — ignore, write text onlyundefined — like false if text === url else like truefallback — like above, other keys are serialized into attributes (only id is now defined, but there is no reason for limitation)@Qix- I don't really know if detection for this feature is even possible.
It may be enabled on level 3 by default.
And there should be new key in output of supports-color with overrides:
level on Chalk constructor)Oh, now I found sindresorhus/terminal-link
I think it's way too early to add this to Chalk, if at all. I like to see it more widely supported first. For now, we can just recommend terminal-link. Honestly not even sure if it makes sense to have this in Chalk. Chalk is for visual styling, while hyperlinks are functional. This is a slippery slope. If we accept this, we should expect to get requests to support other ansi escape codes, like hiding the cursor, etc.
terminal-link is great, however I wish use it with stderr :-D And many tools may want too because of possibility to link local files (I like vscode:/file/${path}:${line}:${column}) and issues on the web...
All diagnostics should go to stderr
But definitely I will be very happy if you mention terminal-link in readme…
Agreed, I think it's out of scope for chalk.
@langpavel I would be happy to add support for stderr in terminal-link ;)
Most helpful comment
@langpavel I would be happy to add support for
stderrinterminal-link;)https://github.com/sindresorhus/terminal-link/issues/4