supports-hyperlinks 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.js +9 -7
- package/index.d.ts +25 -5
- package/index.js +43 -31
- package/license +1 -0
- package/package.json +19 -29
- package/readme.md +4 -13
package/browser.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
export function createSupportsHyperlinks() {
|
2
|
+
return false;
|
3
|
+
}
|
4
|
+
|
5
|
+
const supportsHyperlinks = {
|
6
|
+
stdout: createSupportsHyperlinks(),
|
7
|
+
stderr: createSupportsHyperlinks(),
|
8
8
|
};
|
9
|
+
|
10
|
+
export default supportsHyperlinks;
|
package/index.d.ts
CHANGED
@@ -1,5 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
/**
|
2
|
+
Creates a supports hyperlinks check for a given stream.
|
3
|
+
|
4
|
+
@param stream - Optional stream to check for hyperlink support.
|
5
|
+
@returns boolean indicating whether hyperlinks are supported.
|
6
|
+
*/
|
7
|
+
export function createSupportsHyperlinks(stream?: {isTTY?: boolean}): boolean;
|
8
|
+
|
9
|
+
/**
|
10
|
+
Object containing hyperlink support status for stdout and stderr.
|
11
|
+
*/
|
12
|
+
type SupportsHyperlinks = {
|
13
|
+
/**
|
14
|
+
Whether stdout supports hyperlinks.
|
15
|
+
*/
|
16
|
+
stdout: boolean;
|
17
|
+
/**
|
18
|
+
Whether stderr supports hyperlinks.
|
19
|
+
*/
|
20
|
+
stderr: boolean;
|
21
|
+
};
|
22
|
+
|
23
|
+
declare const supportsHyperlinks: SupportsHyperlinks;
|
24
|
+
|
25
|
+
export default supportsHyperlinks;
|
package/index.js
CHANGED
@@ -1,35 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@param {string} versionString
|
7
|
-
@returns {{ major: number, minor: number, patch: number }}
|
8
|
-
*/
|
9
|
-
function parseVersion(versionString) {
|
1
|
+
import process from 'node:process';
|
2
|
+
import {createSupportsColor} from 'supports-color';
|
3
|
+
import hasFlag from 'has-flag';
|
4
|
+
|
5
|
+
function parseVersion(versionString = '') {
|
10
6
|
if (/^\d{3,4}$/.test(versionString)) {
|
11
7
|
// Env var doesn't always use dots. example: 4601 => 46.1.0
|
12
|
-
const
|
8
|
+
const match = /(\d{1,2})(\d{2})/.exec(versionString) ?? [];
|
13
9
|
return {
|
14
10
|
major: 0,
|
15
|
-
minor: parseInt(
|
16
|
-
patch: parseInt(
|
11
|
+
minor: Number.parseInt(match[1], 10),
|
12
|
+
patch: Number.parseInt(match[2], 10),
|
17
13
|
};
|
18
14
|
}
|
19
15
|
|
20
|
-
const versions = (versionString
|
16
|
+
const versions = (versionString ?? '').split('.').map(n => Number.parseInt(n, 10));
|
21
17
|
return {
|
22
18
|
major: versions[0],
|
23
19
|
minor: versions[1],
|
24
|
-
patch: versions[2]
|
20
|
+
patch: versions[2],
|
25
21
|
};
|
26
22
|
}
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
@returns {boolean}
|
31
|
-
*/
|
32
|
-
function supportsHyperlink(stream) {
|
24
|
+
// eslint-disable-next-line complexity
|
25
|
+
export function createSupportsHyperlinks(stream) {
|
33
26
|
const {
|
34
27
|
CI,
|
35
28
|
FORCE_HYPERLINK,
|
@@ -37,11 +30,12 @@ function supportsHyperlink(stream) {
|
|
37
30
|
TEAMCITY_VERSION,
|
38
31
|
TERM_PROGRAM,
|
39
32
|
TERM_PROGRAM_VERSION,
|
40
|
-
VTE_VERSION
|
33
|
+
VTE_VERSION,
|
34
|
+
TERM,
|
41
35
|
} = process.env;
|
42
36
|
|
43
37
|
if (FORCE_HYPERLINK) {
|
44
|
-
return !(FORCE_HYPERLINK.length > 0 && parseInt(FORCE_HYPERLINK, 10) === 0);
|
38
|
+
return !(FORCE_HYPERLINK.length > 0 && Number.parseInt(FORCE_HYPERLINK, 10) === 0);
|
45
39
|
}
|
46
40
|
|
47
41
|
if (hasFlag('no-hyperlink') || hasFlag('no-hyperlinks') || hasFlag('hyperlink=false') || hasFlag('hyperlink=never')) {
|
@@ -58,7 +52,7 @@ function supportsHyperlink(stream) {
|
|
58
52
|
}
|
59
53
|
|
60
54
|
// If they specify no colors, they probably don't want hyperlinks.
|
61
|
-
if (!
|
55
|
+
if (!createSupportsColor(stream)) {
|
62
56
|
return false;
|
63
57
|
}
|
64
58
|
|
@@ -84,20 +78,29 @@ function supportsHyperlink(stream) {
|
|
84
78
|
}
|
85
79
|
|
86
80
|
if (TERM_PROGRAM) {
|
87
|
-
const version = parseVersion(TERM_PROGRAM_VERSION
|
81
|
+
const version = parseVersion(TERM_PROGRAM_VERSION);
|
88
82
|
|
89
83
|
switch (TERM_PROGRAM) {
|
90
|
-
case 'iTerm.app':
|
84
|
+
case 'iTerm.app': {
|
91
85
|
if (version.major === 3) {
|
92
86
|
return version.minor >= 1;
|
93
87
|
}
|
94
88
|
|
95
89
|
return version.major > 3;
|
96
|
-
|
97
|
-
|
98
|
-
case '
|
90
|
+
}
|
91
|
+
|
92
|
+
case 'WezTerm': {
|
93
|
+
return version.major >= 20_200_620;
|
94
|
+
}
|
95
|
+
|
96
|
+
case 'vscode': {
|
99
97
|
// eslint-disable-next-line no-mixed-operators
|
100
98
|
return version.major > 1 || version.major === 1 && version.minor >= 72;
|
99
|
+
}
|
100
|
+
|
101
|
+
case 'ghostty': {
|
102
|
+
return true;
|
103
|
+
}
|
101
104
|
// No default
|
102
105
|
}
|
103
106
|
}
|
@@ -112,11 +115,20 @@ function supportsHyperlink(stream) {
|
|
112
115
|
return version.major > 0 || version.minor >= 50;
|
113
116
|
}
|
114
117
|
|
118
|
+
switch (TERM) {
|
119
|
+
case 'alacritty': {
|
120
|
+
// Support added in v0.11 (2022-10-13)
|
121
|
+
return true;
|
122
|
+
}
|
123
|
+
// No default
|
124
|
+
}
|
125
|
+
|
115
126
|
return false;
|
116
127
|
}
|
117
128
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
stderr: supportsHyperlink(process.stderr)
|
129
|
+
const supportsHyperlinks = {
|
130
|
+
stdout: createSupportsHyperlinks(process.stdout),
|
131
|
+
stderr: createSupportsHyperlinks(process.stderr),
|
122
132
|
};
|
133
|
+
|
134
|
+
export default supportsHyperlinks;
|
package/license
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
3
4
|
Copyright (c) James Talmage <james@talmage.io> (https://github.com/jamestalmage)
|
4
5
|
|
5
6
|
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:
|
package/package.json
CHANGED
@@ -1,27 +1,21 @@
|
|
1
1
|
{
|
2
2
|
"name": "supports-hyperlinks",
|
3
|
-
"version": "
|
4
|
-
"description": "Detect
|
3
|
+
"version": "4.0.0",
|
4
|
+
"description": "Detect whether a terminal supports hyperlinks",
|
5
5
|
"license": "MIT",
|
6
|
-
"repository": "
|
7
|
-
"funding": "https://github.com/
|
8
|
-
"
|
9
|
-
"name": "James Talmage",
|
10
|
-
"email": "james@talmage.io",
|
11
|
-
"url": "github.com/jamestalmage"
|
12
|
-
},
|
6
|
+
"repository": "chalk/supports-hyperlinks",
|
7
|
+
"funding": "https://github.com/chalk/supports-hyperlinks?sponsor=1",
|
8
|
+
"type": "module",
|
13
9
|
"exports": {
|
14
10
|
"types": "./index.d.ts",
|
15
11
|
"default": "./index.js"
|
16
12
|
},
|
17
13
|
"sideEffects": false,
|
18
14
|
"engines": {
|
19
|
-
"node": ">=
|
15
|
+
"node": ">=20"
|
20
16
|
},
|
21
17
|
"scripts": {
|
22
|
-
"
|
23
|
-
"test": "xo && nyc ava && tsc",
|
24
|
-
"create-types": "tsc --project declaration.tsconfig.json"
|
18
|
+
"test": "xo && ava && tsc index.d.ts"
|
25
19
|
},
|
26
20
|
"files": [
|
27
21
|
"index.js",
|
@@ -33,25 +27,21 @@
|
|
33
27
|
"link",
|
34
28
|
"terminal",
|
35
29
|
"hyperlink",
|
36
|
-
"cli"
|
30
|
+
"cli",
|
31
|
+
"detect",
|
32
|
+
"check",
|
33
|
+
"ansi",
|
34
|
+
"escapes",
|
35
|
+
"console"
|
37
36
|
],
|
38
37
|
"dependencies": {
|
39
|
-
"has-flag": "^
|
40
|
-
"supports-color": "^
|
38
|
+
"has-flag": "^5.0.1",
|
39
|
+
"supports-color": "^10.0.0"
|
41
40
|
},
|
42
41
|
"devDependencies": {
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"nyc": "^14.1.1",
|
48
|
-
"typescript": "^4.9.5",
|
49
|
-
"xo": "^0.24.0"
|
50
|
-
},
|
51
|
-
"nyc": {
|
52
|
-
"reporter": [
|
53
|
-
"lcov",
|
54
|
-
"text"
|
55
|
-
]
|
42
|
+
"ava": "^6.2.0",
|
43
|
+
"codecov": "^3.8.3",
|
44
|
+
"typescript": "^5.8.2",
|
45
|
+
"xo": "^0.60.0"
|
56
46
|
}
|
57
47
|
}
|
package/readme.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# supports-hyperlinks
|
1
|
+
# supports-hyperlinks
|
2
2
|
|
3
|
-
> Detect whether a terminal
|
3
|
+
> Detect whether a terminal supports hyperlinks
|
4
4
|
|
5
5
|
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.
|
6
6
|
|
7
7
|
This module allows you to detect if hyperlinks are supported in the current Terminal.
|
8
8
|
|
9
|
-
As this is a new development, we anticipate the list of supported
|
9
|
+
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.
|
10
10
|
|
11
11
|
## Install
|
12
12
|
|
@@ -14,11 +14,10 @@ As this is a new development, we anticipate the list of supported Terminals to g
|
|
14
14
|
npm install supports-hyperlinks
|
15
15
|
```
|
16
16
|
|
17
|
-
|
18
17
|
## Usage
|
19
18
|
|
20
19
|
```js
|
21
|
-
|
20
|
+
import supportsHyperlinks from 'supports-hyperlinks';
|
22
21
|
|
23
22
|
if (supportsHyperlinks.stdout) {
|
24
23
|
console.log('Terminal stdout supports hyperlinks');
|
@@ -38,11 +37,3 @@ Returns an `Object` with a `stdout` and `stderr` property for testing either str
|
|
38
37
|
Obeys the `--no-hyperlinks`, `--hyperlink=always`, and `--hyperlink=never` CLI flags.
|
39
38
|
|
40
39
|
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.
|
41
|
-
|
42
|
-
## Related
|
43
|
-
|
44
|
-
* [`hyperlinker`](https://github.com/jamestalmage/hyperlinker): Write hyperlinks for the Terminal.
|
45
|
-
|
46
|
-
## License
|
47
|
-
|
48
|
-
MIT © [James Talmage](https://github.com/jamestalmage)
|