Create clickable links in the terminal

Overview

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

Comments
  • Add stderr support

    Add stderr support

    Closes #4 and replaces PR #5 (apologies for messing up the previous PR, my git skills are somewhat lacking)

    This PR allows you to do the following:

    // stdout
    terminalLink('Google', 'https://google.com');
    terminalLink.isSupported;
    
    // stderr
    terminalLink.stderr('Google', 'https://google.com');
    terminalLink.stderr.isSupported;
    
    opened by tom-sherman 7
  • Stderr support

    Stderr support

    opened by sindresorhus 7
  • WIP: Add `stderr` support

    WIP: Add `stderr` support

    Closes #4

    This PR allows you to do the following:

    // stdout
    terminalLink('Google', 'https://google.com');
    terminalLink.isSupported;
    
    // stderr
    terminalLink.stderr('Google', 'https://google.com');
    terminalLink.stderr.isSupported;
    
    opened by tom-sherman 5
  • 3.0 doesn't support cjs

    3.0 doesn't support cjs

    Providing a cjs build would be nice for those of use not able to use esm. In my case other tooling (qunit) is incompatible even though my lowest supported node version (12.x) is compatible with this.

    opened by runspired 3
  • I have error with  dependencies

    I have error with dependencies "supports-hyperlinks"

    why terminal-link is ESM, but supports-hyperlinks is commonjs ? when i use terminal-link with ts-node xxx.ts, i get an error:

    Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: xxxxx/node_modules/terminal-link/index.js
    
    opened by m7yue 2
  • Add `fallback: false` option to disable the fallback

    Add `fallback: false` option to disable the fallback

    This PR updates terminal-link to support disabling the fallback entirely and updates the TS types and documentation to reflect this change.

    This PR enables us to update ink-link to support disabling the fallback with an option:

    • https://github.com/sindresorhus/ink-link/issues/4
    • https://github.com/sindresorhus/ink-link/pull/5/files

    Original request: https://github.com/sindresorhus/ink-link/pull/5/files#r326882650

    opened by colinking 1
  • Add TypeScript definition

    Add TypeScript definition

    This is my typescript

    declare function terminalLink(
      text: string,
      url: string,
      options?: { fallback: (text: string, url: string) => string }
    ): string;
    
    declare module "terminal-link" {
      export = terminalLink;
    }
    
    help wanted 
    opened by kamontat 1
  • Allow `fallback` to be `true`

    Allow `fallback` to be `true`

    This is a follow-up PR to: https://github.com/sindresorhus/terminal-link/pull/13

    In that PR, fallback could only be a function or false. If it was set to true, it would produce an error because it would attempt to execute it as if it was a function:

      Error thrown in test:
    
      TypeError {
        message: 'options.fallback is not a function',
      }
    

    This means that upstream consumers would need to replace fallback=true with fallback=undefined, which isn't a great experience.

    This PR just updates terminal-link to produce the default fallback if fallback=true, and updates the associated documentation.

    opened by colinking 0
  • Add TypeScript definition

    Add TypeScript definition

    Fixes #2

    Style Guide Checklist

    • [x] Use tab-indentation and semicolons.
    • [x] The definition should target the latest TypeScript version.
    • [x] Exported properties/methods should be documented (see below).
    • [x] The definition should be tested (see below).
    • [x] Ensure you're not falling for any of the common mistakes.
    • [x] For packages with a default export, use export default foo;, not export = foo;. You will have to add module.exports.default = foo; to the index.js file.
    • [x] If the entry file in the package is named index.js, name the type definition file index.d.ts and put it in root.
      You don't need to add a typings field to package.json as TypeScript will infer it from the name.
    • [x] Add the type definition file to the files field in package.json.
    • [x] The pull request should have the title Add TypeScript definition. (Copy-paste it so you don't get it wrong)
    • [ ] Ignore any Travis linting failures. I will fix them after merging.
    • [ ] Help review other pull requests that adds a type definition.
    opened by danthegoodman 0
  • Clickable links including

    Clickable links including "zero width space" in URL

    I've already reported this issue on the Netlify CLI repo https://github.com/netlify/cli/issues/4311

    I'm using VSCode and am working on a project that uses the Netlify CLI. They print out the URLs to the serverless functions as they're loaded. These URLs include a "zero width space" (U+200B).

    ◈ Loaded function api (​http://localhost:8888/.netlify/functions/api​).
    ◈ Loaded function render (​http://localhost:8888/.netlify/functions/render​).
    

    Clicking those links in the VSCode terminal includes the zero width space, producing URLs that look like

    http://localhost:8888/.netlify/functions/api%E2%80%8B
    

    I know there is a fallback that adds the character for unsupported terminals. VSCode isn't specifically on the support list, but it can also use lots of different terminals so it may be listed as one of them. Even if none are supported, VSCode's terminal seems to make any URL-like string clickable, for example:

    image

    I'm curious if it would be safe for me to write a PR for the Netlify CLI that turns it off or returns a normal space?

    opened by Soviut 2
Releases(v3.0.0)
  • v3.0.0(Apr 18, 2021)

  • v2.1.1(Dec 18, 2019)

  • v2.1.0(Dec 18, 2019)

  • v2.0.0(Sep 1, 2019)

    Breaking:

    • Require Node.js 8 (#10) e4625fc
    • Add whitespace to fallback output so the URL is correctly linkified (#12) d879caf This should not be breaking for most people, unless you do equality testing on the fallback output.

    Breaking for TypeScript users:

    • Only use a CommonJS export for the TypeScript definition You need to change import terminalLink from 'terminal-link'; to import terminalLink = require('terminal-link');

    Enhancements:

    • Add stderr support (#9) 1d248b6

    https://github.com/sindresorhus/terminal-link/compare/v1.3.0...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Apr 6, 2019)

    • Refactor TypeScript definition to CommonJS compatible export (#6) a649623

    https://github.com/sindresorhus/terminal-link/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Dec 22, 2018)

Owner
Sindre Sorhus
Full-Time Open-Sourcerer. Wants more empathy & kindness in open source. Focuses on Swift & JavaScript. Makes macOS apps, CLI tools, npm packages. Likes unicorns
Sindre Sorhus
Terminal ui for discord with interactive terminal

dickord why No fucking clue i was bored or something. why does it look dogshit Try and find a node module that supports terminal functions like trauma

Hima 3 Nov 7, 2022
📜 Create mutable log lines into the terminal, and give life to your logs!

Because Logging can be pretty and fun Installation $ npm install draftlog What it does It allows you to re-write a line of your log after being writt

Ivan Seidel 1.2k Dec 31, 2022
Sublime-like terminal-based text editor

slap ?? slap is a Sublime-like terminal-based text editor that strives to make editing from the terminal easier. It has: first-class mouse support (ev

slap 6.1k Jan 1, 2023
A terminal-to-gif recorder minus the headaches.

ttystudio A terminal-to-gif recorder minus the headaches. Record your terminal and compile it to a GIF or APNG without any external dependencies, bash

Christopher Jeffrey (JJ) 3.2k Dec 23, 2022
rtail(1) - Terminal output to the browser in seconds, using UNIX pipes.

rtail(1) Terminal output to the browser in seconds, using UNIX pipes. rtail is a command line utility that grabs every line in stdin and broadcasts it

Kilian Ciuffolo 1.6k Jan 6, 2023
Pipeable javascript. Quickly filter, map, and reduce from the terminal

Pipeable JavaScript - another utility like sed/awk/wc... but with JS! Quickly filter, map and reduce from the command line. Features a streaming API.

Daniel St. Jules 410 Dec 10, 2022
Translations with speech synthesis in your terminal as a node package

Normit Normit is an easy way to translate stuff in your terminal. You can check out its Ruby gem version termit. Installation npm install normit -g Us

Paweł Urbanek 234 Jan 1, 2023
Terminal recorder: Record your termial session into HTML

terminal-recorder Terminal recorder allows you to record your bash session, and export it to html so then you can share it with your friends. GitHub P

Cristian Cortez 104 Mar 3, 2022
Terminal task list

listr Terminal task list Install $ npm install --save listr Usage const execa = require('execa'); const Listr = require('listr'); const tasks = new

Sam Verschueren 3.1k Jan 3, 2023
Display images in the terminal

terminal-image Display images in the terminal Works in any terminal that supports colors. In iTerm, the image will be displayed in full resolution, si

Sindre Sorhus 905 Dec 25, 2022
:rainbow: Beautiful color gradients in terminal output

gradient-string Beautiful color gradients in terminal output Install $ npm i gradient-string Usage const gradient = require('gradient-string'); cons

Boris K 864 Jan 3, 2023
Reliably get the terminal window size

term-size Reliably get the terminal window size Because process.stdout.columns doesn't exist when run non-interactively, for example, in a child proce

Sindre Sorhus 132 Oct 11, 2022
Truncate a string to a specific width in the terminal

cli-truncate Truncate a string to a specific width in the terminal Gracefully handles ANSI escapes. Like a string styled with chalk. It also supports

Sindre Sorhus 78 Oct 10, 2022
Execute shell commands in terminal

Execute shell commands in terminal

skanehira 9 Dec 11, 2021
Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Nom Does this ever happen to you? You happily code away on a project, navigating the command line like a pro, testing, error logging, installing packa

Meike Hankewicz 5 Apr 26, 2022
Just a minimal library to do some terminal stuff.

Termctl A simple library to do some basic terminal stuff. Usage const termctl = require("termctl"); Note: We have tested this on Linux Mint and Window

Biraj 4 Sep 28, 2021
A terminal for a more modern age

Downloads: Latest release Repositories: Debian/Ubuntu-based, RPM-based Latest nightly build This README is also available in: Korean 简体中文 Tabby (forme

null 41.8k Dec 30, 2022
DataENV is a cli tool that allows you to save data temporarily using your terminal.

DataEnv CLI Instllation npm install -g dataenv Usage Table of Contents LocalStorage npx dataenv save Parameters npx dataenv show Parameters npx dataen

PGamerX 2 Feb 5, 2022