pax_global_header00006660000000000000000000000064151233004540014507gustar00rootroot0000000000000052 comment=f155c11cd08f71f4b573ae7d276a38279a247272 chalk-supports-hyperlinks-b0816bf/000077500000000000000000000000001512330045400172665ustar00rootroot00000000000000chalk-supports-hyperlinks-b0816bf/.editorconfig000066400000000000000000000002571512330045400217470ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 chalk-supports-hyperlinks-b0816bf/.gitattributes000066400000000000000000000000231512330045400221540ustar00rootroot00000000000000* text=auto eol=lf chalk-supports-hyperlinks-b0816bf/.github/000077500000000000000000000000001512330045400206265ustar00rootroot00000000000000chalk-supports-hyperlinks-b0816bf/.github/security.md000066400000000000000000000002631512330045400230200ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. chalk-supports-hyperlinks-b0816bf/.github/workflows/000077500000000000000000000000001512330045400226635ustar00rootroot00000000000000chalk-supports-hyperlinks-b0816bf/.github/workflows/main.yml000066400000000000000000000006451512330045400243370ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 22 - 20 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test chalk-supports-hyperlinks-b0816bf/.gitignore000066400000000000000000000000541512330045400212550ustar00rootroot00000000000000node_modules yarn.lock .nyc_output coverage chalk-supports-hyperlinks-b0816bf/.npmrc000066400000000000000000000000231512330045400204010ustar00rootroot00000000000000package-lock=false chalk-supports-hyperlinks-b0816bf/browser.js000066400000000000000000000003151512330045400213060ustar00rootroot00000000000000export function createSupportsHyperlinks() { return false; } const supportsHyperlinks = { stdout: createSupportsHyperlinks(), stderr: createSupportsHyperlinks(), }; export default supportsHyperlinks; chalk-supports-hyperlinks-b0816bf/index.d.ts000066400000000000000000000011211512330045400211620ustar00rootroot00000000000000/** Creates a supports hyperlinks check for a given stream. @param stream - Optional stream to check for hyperlink support. @returns boolean indicating whether hyperlinks are supported. */ export function createSupportsHyperlinks(stream?: {isTTY?: boolean}): boolean; /** Object containing hyperlink support status for stdout and stderr. */ type SupportsHyperlinks = { /** Whether stdout supports hyperlinks. */ stdout: boolean; /** Whether stderr supports hyperlinks. */ stderr: boolean; }; declare const supportsHyperlinks: SupportsHyperlinks; export default supportsHyperlinks; chalk-supports-hyperlinks-b0816bf/index.js000066400000000000000000000064301512330045400207360ustar00rootroot00000000000000import process from 'node:process'; import {createSupportsColor} from 'supports-color'; import hasFlag from 'has-flag'; function parseVersion(versionString = '') { if (/^\d{3,4}$/.test(versionString)) { // Env var doesn't always use dots. example: 4601 => 46.1.0 const match = /(\d{1,2})(\d{2})/.exec(versionString) ?? []; return { major: 0, minor: Number.parseInt(match[1], 10), patch: Number.parseInt(match[2], 10), }; } const versions = (versionString ?? '').split('.').map(n => Number.parseInt(n, 10)); return { major: versions[0], minor: versions[1], patch: versions[2], }; } // eslint-disable-next-line complexity export function createSupportsHyperlinks(stream) { const { CI, CURSOR_TRACE_ID, FORCE_HYPERLINK, NETLIFY, TEAMCITY_VERSION, TERM_PROGRAM, TERM_PROGRAM_VERSION, VTE_VERSION, TERM, } = process.env; if (FORCE_HYPERLINK) { return !(FORCE_HYPERLINK.length > 0 && Number.parseInt(FORCE_HYPERLINK, 10) === 0); } if (hasFlag('no-hyperlink') || hasFlag('no-hyperlinks') || hasFlag('hyperlink=false') || hasFlag('hyperlink=never')) { return false; } if (hasFlag('hyperlink=true') || hasFlag('hyperlink=always')) { return true; } // Netlify does not run a TTY, it does not need `supportsColor` check if (NETLIFY) { return true; } // If they specify no colors, they probably don't want hyperlinks. if (!createSupportsColor(stream)) { return false; } if (stream && !stream.isTTY) { return false; } // Windows Terminal if ('WT_SESSION' in process.env) { return true; } if (process.platform === 'win32') { return false; } if (CI) { return false; } if (TEAMCITY_VERSION) { return false; } if (TERM_PROGRAM) { const version = parseVersion(TERM_PROGRAM_VERSION); switch (TERM_PROGRAM) { case 'iTerm.app': { if (version.major === 3) { return version.minor >= 1; } return version.major > 3; } case 'WezTerm': { // WezTerm packaged by Nix uses their own version scheme. if (/^0-unstable-\d{4}-\d{2}-\d{2}$/.test(TERM_PROGRAM_VERSION)) { const date = TERM_PROGRAM_VERSION.slice('0-unstable-'.length); return date >= '2020-06-20'; } // This number is a date and reads better grouped as such. // eslint-disable-next-line unicorn/numeric-separators-style return version.major >= 2020_06_20; } case 'vscode': { // Cursor forked VS Code and supports hyperlinks in 0.x.x if (CURSOR_TRACE_ID) { return true; } // eslint-disable-next-line @stylistic/no-mixed-operators return version.major > 1 || version.major === 1 && version.minor >= 72; } case 'ghostty': { return true; } case 'zed': { return true; } // No default } } if (VTE_VERSION) { // 0.50.0 was supposed to support hyperlinks, but throws a segfault if (VTE_VERSION === '0.50.0') { return false; } const version = parseVersion(VTE_VERSION); return version.major > 0 || version.minor >= 50; } switch (TERM) { case 'alacritty': { // Support added in v0.11 (2022-10-13) return true; } case 'xterm-kitty': { return true; } // No default } return false; } const supportsHyperlinks = { stdout: createSupportsHyperlinks(process.stdout), stderr: createSupportsHyperlinks(process.stderr), }; export default supportsHyperlinks; chalk-supports-hyperlinks-b0816bf/license000066400000000000000000000022561512330045400206400ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Copyright (c) James Talmage (https://github.com/jamestalmage) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. chalk-supports-hyperlinks-b0816bf/package.json000066400000000000000000000015511512330045400215560ustar00rootroot00000000000000{ "name": "supports-hyperlinks", "version": "4.4.0", "description": "Detect whether a terminal supports hyperlinks", "license": "MIT", "repository": "chalk/supports-hyperlinks", "funding": "https://github.com/chalk/supports-hyperlinks?sponsor=1", "type": "module", "exports": { "types": "./index.d.ts", "default": "./index.js" }, "sideEffects": false, "engines": { "node": ">=20" }, "scripts": { "test": "xo && ava && tsc --lib es2022 index.d.ts" }, "files": [ "index.js", "index.d.ts", "browser.js" ], "browser": "browser.js", "keywords": [ "link", "terminal", "hyperlink", "cli", "detect", "check", "ansi", "escapes", "console" ], "dependencies": { "has-flag": "^5.0.1", "supports-color": "^10.2.2" }, "devDependencies": { "ava": "^6.4.1", "codecov": "^3.8.3", "typescript": "^5.9.3", "xo": "^1.2.3" } } chalk-supports-hyperlinks-b0816bf/readme.md000066400000000000000000000033741512330045400210540ustar00rootroot00000000000000# supports-hyperlinks > Detect whether a terminal supports hyperlinks Terminal emulators are [starting to support hyperlinks](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). While many terminals have long detected URL's and linkified them, allowing you to Command-Click or Control-Click them to open a browser, you were forced to print the long unsightly URL's on the screen. As of spring 2017 [a few terminals](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) began supporting HTML like links, where the link text and destination could be specified separately. This module allows you to detect if hyperlinks are supported in the current Terminal. As this is a new development, we anticipate the list of supported terminals to grow rapidly. Please open an issue or submit a PR as new terminals implement support. ## Install ```sh npm install supports-hyperlinks ``` ## Usage ```js import supportsHyperlinks from 'supports-hyperlinks'; if (supportsHyperlinks.stdout) { console.log('Terminal stdout supports hyperlinks'); } if (supportsHyperlinks.stderr) { console.log('Terminal stderr supports hyperlinks'); } ``` ## API Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is a `boolean`, indicating whether or not hyperlinks are supported. ## Info Obeys the `--no-hyperlinks`, `--hyperlink=always`, and `--hyperlink=never` CLI flags. Can be overridden by the user with the flags `--hyperlinks=always` and `--no-hyperlinks`. For situations where using those flags are not possible, add the environment variable `FORCE_HYPERLINK=1` to forcefully enable hyperlinks or `FORCE_HYPERLINK=0` to forcefully disable. The use of `FORCE_HYPERLINK` overrides all other hyperlink support checks. chalk-supports-hyperlinks-b0816bf/test.js000066400000000000000000000207731512330045400206140ustar00rootroot00000000000000import process from 'node:process'; import test from 'ava'; import {createSupportsHyperlinks} from './index.js'; const isSupported = ({ platform = 'darwin', env = {}, argv = [], stream, }) => { const oldPlatform = process.platform; const oldEnv = process.env; const oldArgv = process.argv; Object.defineProperties(process, { platform: {value: platform}, env: {value: env}, argv: {value: [process.argv[0], ...argv]}, }); const result = createSupportsHyperlinks(stream); Object.defineProperties(process, { platform: {value: oldPlatform}, env: {value: oldEnv}, argv: {value: oldArgv}, }); return result; }; test('supported iTerm.app 3.1, tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '3.1.0', }, stream: { isTTY: true, }, })); }); test('supported iTerm.app 3.1, no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '3.1.0', }, })); }); test('supported iTerm.app 4.0, no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '4.0.0', }, })); }); test('not supported iTerm 3.0, tty stream', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '3.0.0', }, stream: { isTTY: true, }, })); }); test('not supported iTerm 3.1, non-tty stream', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '3.1.0', }, stream: { isTTY: false, }, })); }); test('not supported WezTerm 20200620 no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'WezTerm', TERM_PROGRAM_VERSION: '20200620-160318-e00b076c', }, })); }); test('not supported WezTerm 20200608 no stream supplied', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'WezTerm', TERM_PROGRAM_VERSION: '20200608-110940-3fb3a61', }, })); }); test('supported WezTerm 20200620, tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'WezTerm', TERM_PROGRAM_VERSION: '20200620-160318-e00b076c', }, stream: { isTTY: true, }, })); }); test('not supported WezTerm 20200608, tty stream', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'WezTerm', TERM_PROGRAM_VERSION: '20200608-110940-3fb3a61', }, stream: { isTTY: true, }, })); }); test('supported WezTerm 20200620 packaged by Nix, tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'WezTerm', TERM_PROGRAM_VERSION: '0-unstable-2020-06-20', }, stream: { isTTY: true, }, })); }); test('not supported WezTerm 20200608 packaged by Nix, tty stream', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'WezTerm', TERM_PROGRAM_VERSION: '0-unstable-2020-06-08', }, stream: { isTTY: true, }, })); }); test('not supported vscode <= 1.0 no stream supplied', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '0.72.0', }, })); }); test('not supported vscode <= 1.0 tty stream', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '0.72.0', }, stream: { isTTY: true, }, })); }); test('supported vscode 2.70.0 no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '2.70.0', }, })); }); test('supported vscode 2.70.0 tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '2.70.0', }, stream: { isTTY: true, }, })); }); test('not supported vscode 1.0 no stream supplied', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '1.0.0', }, })); }); test('not supported vscode 1.0 tty stream', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '1.0.0', }, stream: { isTTY: true, }, })); }); test('supported vscode >= 1.72.0 no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '1.72.0', }, })); }); test('supported vscode >= 1.72.0 tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '1.72.0', }, stream: { isTTY: true, }, })); }); test('supported Cursor (vscode fork) no stream supplied', t => { t.true(isSupported({ env: { CURSOR_TRACE_ID: 'some-trace-id', TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '0.49.6', }, })); }); test('supported Cursor (vscode fork) tty stream', t => { t.true(isSupported({ env: { CURSOR_TRACE_ID: 'some-trace-id', TERM_PROGRAM: 'vscode', TERM_PROGRAM_VERSION: '0.49.6', }, stream: { isTTY: true, }, })); }); test('supported ghostty no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'ghostty', }, })); }); test('supported ghostty tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'ghostty', }, stream: { isTTY: true, }, })); }); test('not supported in VTE 0.50.0', t => { t.false(isSupported({ env: { VTE_VERSION: '0.50.0', }, })); }); test('supported in VTE 0.50.1', t => { t.true(isSupported({ env: { VTE_VERSION: '0.50.1', }, })); }); test('supported in VTE 0.51.0', t => { t.true(isSupported({ env: { VTE_VERSION: '0.51.0', }, })); }); test('supported in VTE 1.0.0', t => { t.true(isSupported({ env: { VTE_VERSION: '1.0.0', }, })); }); test('not supported in VTE 4601 (0.46.1)', t => { t.false(isSupported({ env: { VTE_VERSION: '4601', }, })); }); test('supported in VTE 5105 (0.51.5)', t => { t.true(isSupported({ env: { VTE_VERSION: '5105', }, })); }); test('supported in alacritty', t => { t.true(isSupported({ env: { TERM: 'alacritty', }, })); }); test('supported in kitty', t => { t.true(isSupported({ env: { TERM: 'xterm-kitty', }, })); }); test('supported zed no stream supplied', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'zed', }, })); }); test('supported zed tty stream', t => { t.true(isSupported({ env: { TERM_PROGRAM: 'zed', }, stream: { isTTY: true, }, })); }); test('empty env not supported', t => { t.false(isSupported({env: {}})); }); test.failing('no-color flag disables support', t => { t.false(isSupported({ argv: ['--no-color'], env: { VTE_VERSION: '1.0.0', }, })); }); test('not supported if no environment variables are set', t => { t.false(isSupported({})); }); test('supported if hyperlink=true flag is set', t => { t.true(isSupported({ argv: ['--hyperlink=true'], })); }); test('supported if hyperlink=always flag is set', t => { t.true(isSupported({ argv: ['--hyperlink=always'], })); }); test('hyperlink=false flag disables support', t => { t.false(isSupported({ argv: ['--hyperlink=false'], env: { VTE_VERSION: '1.0.0', }, })); }); test('hyperlink=never flag disables support', t => { t.false(isSupported({ argv: ['--hyperlink=never'], env: { VTE_VERSION: '1.0.0', }, })); }); test('no-hyperlink flag disables support', t => { t.false(isSupported({ argv: ['--no-hyperlink'], env: { VTE_VERSION: '1.0.0', }, })); }); test('no-hyperlinks flag disables support', t => { t.false(isSupported({ argv: ['--no-hyperlinks'], env: { VTE_VERSION: '1.0.0', }, })); }); test('hyperlink=always flag takes precedence over no-color flags', t => { t.true(isSupported({ argv: ['--no-color', '--hyperlink=always'], env: { VTE_VERSION: '1.0.0', }, })); }); test('not supported on win32 platform', t => { t.false(isSupported({ platform: 'win32', env: { VTE_VERSION: '1.0.0', }, })); }); test('hyperlink=always forces support on win32 platform', t => { t.true(isSupported({ argv: ['--hyperlink=always'], platform: 'win32', })); }); test('disabled in CI', t => { t.false(isSupported({ env: { CI: 'Travis', VTE_VERSION: '1.0.0', }, })); }); test('disabled in TEAMCITY', t => { t.false(isSupported({ env: { TEAMCITY_VERSION: '10.2.0', VTE_VERSION: '1.0.0', }, })); }); test('enabled in Netlify build logs', t => { t.true(isSupported({ env: { CI: 'true', NETLIFY: 'true', }, })); }); test('not supported if TERM_PROGRAM exists, but TERM_VERSION does not', t => { t.false(isSupported({ env: { TERM_PROGRAM: 'iTerm.app', }, })); }); test('FORCE_HYPERLINK=1 forces hyperlink support', t => { t.true(isSupported({ env: { FORCE_HYPERLINK: '1', }, })); }); test('FORCE_HYPERLINK=0 disables hyperlink support', t => { t.false(isSupported({ argv: ['--hyperlink=always'], env: { FORCE_HYPERLINK: '0', }, })); });