What is terminal-link?
The terminal-link npm package allows you to create clickable links in the terminal. This can be useful for providing users with easy access to URLs directly from the command line.
What are terminal-link's main functionalities?
Basic Link Creation
This feature allows you to create a basic clickable link in the terminal. The link text ('My Website') will be clickable and will direct the user to the specified URL ('https://example.com').
const terminalLink = require('terminal-link');
const link = terminalLink('My Website', 'https://example.com');
console.log(link);
Conditional Link Creation
This feature allows you to create a link that only becomes clickable if the terminal supports it. If not, it will fall back to a plain text URL.
const terminalLink = require('terminal-link');
const link = terminalLink.isSupported ? terminalLink('My Website', 'https://example.com') : 'My Website (https://example.com)';
console.log(link);
Customizing Link Styles
This feature allows you to customize the appearance of the link text using other libraries like chalk. In this example, the link text is styled to be blue and underlined.
const terminalLink = require('terminal-link');
const chalk = require('chalk');
const link = terminalLink(chalk.blue.underline('My Website'), 'https://example.com');
console.log(link);
Other packages similar to terminal-link
ink-link
The ink-link package is used within the Ink framework to create clickable links in React-based terminal applications. It offers similar functionality to terminal-link but is designed to work seamlessly with Ink's component-based architecture.
terminal-link
Create clickable links in the terminal
Install
$ npm install terminal-link
Usage
import terminalLink from 'terminal-link';
const link = terminalLink('My Website', 'https://sindresorhus.com');
console.log(link);
API
terminalLink(text, url, options?)
Create a link for use in stdout.
Supported terminals.
For unsupported terminals, the link will be printed in parens after the text: My website (https://sindresorhus.com)
.
text
Type: string
Text to linkify.
url
Type: string
URL to link to.
options
Type: object
fallback
Type: Function | boolean
Override the default fallback. The function receives the text
and url
as parameters and is expected to return a string.
If set to false
, the fallback will be disabled when a terminal is unsupported.
terminalLink.isSupported
Type: boolean
Check whether the terminal's stdout supports links.
Prefer just using the default fallback or the fallback
option whenever possible.
terminalLink.stderr(text, url, options?)
Create a link for use in stdout.
Same arguments as terminalLink()
.
terminalLink.stderr.isSupported
Type: boolean
Check whether the terminal's stderr supports links.
Prefer just using the default fallback or the fallback
option whenever possible.
Related