Skip to content

Display terminal links in cursor #1998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/itchy-games-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@trigger.dev/sdk": patch
"trigger.dev": patch
---

Display clickable links in Cursor terminal
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
"engine.io-parser@5.2.2": "patches/engine.io-parser@5.2.2.patch",
"graphile-worker@0.16.6": "patches/graphile-worker@0.16.6.patch",
"redlock@5.0.0-beta.2": "patches/redlock@5.0.0-beta.2.patch",
"supports-hyperlinks@2.3.0": "patches/supports-hyperlinks@2.3.0.patch",
"@kubernetes/client-node@1.0.0": "patches/@kubernetes__client-node@1.0.0.patch"
}
}
}
}
4 changes: 3 additions & 1 deletion packages/cli-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@opentelemetry/semantic-conventions": "1.25.1",
"@trigger.dev/build": "workspace:4.0.0-v4-beta.11",
"@trigger.dev/core": "workspace:4.0.0-v4-beta.11",
"ansi-escapes": "^7.0.0",
"c12": "^1.11.1",
"chalk": "^5.2.0",
"chokidar": "^3.6.0",
Expand All @@ -103,6 +104,7 @@
"evt": "^2.4.13",
"fast-npm-meta": "^0.2.2",
"gradient-string": "^2.0.2",
"has-flag": "^5.0.1",
"import-in-the-middle": "1.11.0",
"import-meta-resolve": "^4.1.0",
"jsonc-parser": "3.2.1",
Expand All @@ -123,7 +125,7 @@
"socket.io-client": "4.7.5",
"source-map-support": "0.5.21",
"std-env": "^3.7.0",
"terminal-link": "^3.0.0",
"supports-color": "^10.0.0",
"tiny-invariant": "^1.2.0",
"tinyexec": "^0.3.1",
"tinyglobby": "^0.2.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-v3/src/utilities/cliOutput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from "@clack/prompts";
import chalk from "chalk";
import terminalLink, { Options as TerminalLinkOptions } from "terminal-link";
import { terminalLink, TerminalLinkOptions } from "./terminalLink.js";
import { hasTTY } from "std-env";

export const isInteractive = hasTTY;
Expand Down
160 changes: 160 additions & 0 deletions packages/cli-v3/src/utilities/supportsHyperlinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Copyright (c) James Talmage <james@talmage.io> (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.
*/

import { createSupportsColor } from "supports-color";
import hasFlag from "has-flag";

function parseVersion(versionString = ""): { major: number; minor: number; patch: number } {
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] ?? "0", 10),
patch: Number.parseInt(match[2] ?? "0", 10),
};
}

const versions = (versionString ?? "").split(".").map((n) => Number.parseInt(n, 10));
return {
major: versions[0] ?? 0,
minor: versions[1] ?? 0,
patch: versions[2] ?? 0,
};
}

/**
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: NodeJS.WriteStream): boolean {
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 (CURSOR_TRACE_ID) {
return true;
}

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": {
return version.major >= 20_200_620;
}

case "vscode": {
// eslint-disable-next-line no-mixed-operators
return version.major > 1 || (version.major === 1 && version.minor >= 72);
}

case "ghostty": {
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;
}
// No default
}

return false;
}

/** Object containing hyperlink support status for stdout and stderr. */
const supportsHyperlinks = {
/** Whether stdout supports hyperlinks. */
stdout: createSupportsHyperlinks(process.stdout),
/** Whether stderr supports hyperlinks. */
stderr: createSupportsHyperlinks(process.stderr),
};

export default supportsHyperlinks;
94 changes: 94 additions & 0 deletions packages/cli-v3/src/utilities/terminalLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
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.
*/

import ansiEscapes from "ansi-escapes";
import supportsHyperlinks from "./supportsHyperlinks.js";

export type TerminalLinkOptions = {
/**
Override the default fallback. If false, the fallback will be disabled.
@default `${text} (${url})`
*/
readonly fallback?: ((text: string, url: string) => string) | boolean;
};

/**
Create a clickable link in the terminal's stdout.

[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
For unsupported terminals, the link will be printed in parens after the text: `My website (https://sindresorhus.com)`,
unless the fallback is disabled by setting the `fallback` option to `false`.

@param text - Text to linkify.
@param url - URL to link to.

@example
```
import terminalLink from 'terminal-link';

const link = terminalLink('My Website', 'https://sindresorhus.com');
console.log(link);
```

@deprecated The default fallback is broken in some terminals. Please use `cliLink` instead.
*/
function terminalLink(
text: string,
url: string,
{ target = "stdout", ...options }: { target?: "stdout" | "stderr" } & TerminalLinkOptions = {}
) {
if (!supportsHyperlinks[target]) {
// If the fallback has been explicitly disabled, don't modify the text itself.
if (options.fallback === false) {
return text;
}

return typeof options.fallback === "function"
? options.fallback(text, url)
: `${text} (\u200B${url}\u200B)`;
}

return ansiEscapes.link(text, url);
}
/**
Check whether the terminal supports links.

Prefer just using the default fallback or the `fallback` option whenever possible.
*/
terminalLink.isSupported = supportsHyperlinks.stdout;
terminalLink.stderr = terminalLinkStderr;

/**
Create a clickable link in the terminal's stderr.

[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
For unsupported terminals, the link will be printed in parens after the text: `My website (https://sindresorhus.com)`.

@param text - Text to linkify.
@param url - URL to link to.

@example
```
import terminalLink from 'terminal-link';

const link = terminalLink.stderr('My Website', 'https://sindresorhus.com');
console.error(link);
```
*/
function terminalLinkStderr(text: string, url: string, options: TerminalLinkOptions = {}) {
return terminalLink(text, url, { target: "stderr", ...options });
}

/**
Check whether the terminal's stderr supports links.

Prefer just using the default fallback or the `fallback` option whenever possible.
*/
terminalLinkStderr.isSupported = supportsHyperlinks.stderr;

export { terminalLink };
10 changes: 0 additions & 10 deletions packages/cli-v3/types.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/trigger-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"debug": "^4.3.4",
"evt": "^2.4.13",
"slug": "^6.0.0",
"terminal-link": "^3.0.0",
"ulid": "^2.3.0",
"uncrypto": "^0.1.3",
"uuid": "^9.0.0",
Expand Down
16 changes: 0 additions & 16 deletions patches/supports-hyperlinks@2.3.0.patch

This file was deleted.

Loading
Loading