Skip to content
Closed
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
1 change: 0 additions & 1 deletion packages/cli-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"@opentelemetry/sdk-metrics": "1.30.0",
"@types/archiver": "5.3.2",
"ajv": "8.18.0",
"ansi-escapes": "6.2.1",
"archiver": "5.3.2",
"bottleneck": "2.19.5",
Comment on lines 117 to 119
"chalk": "5.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-kit/src/private/node/content-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {osc8Link} from './hyperlink.js'
import colors from '../../public/node/colors.js'
import {OutputMessage, stringifyMessage} from '../../public/node/output.js'
import {relativizePath} from '../../public/node/path.js'
import ansiEscapes from 'ansi-escapes'
import supportsHyperlinks from 'supports-hyperlinks'
import cjs from 'color-json'
import type {Change} from 'diff'
Expand Down Expand Up @@ -37,7 +37,7 @@ export class LinkContentToken extends ContentToken<OutputMessage> {
const url = this.link ?? ''
const defaultFallback = this.value === this.link ? text : `${text} ( ${url} )`
if (supportsHyperlinks.stdout) {
return ansiEscapes.link(text, url)
return osc8Link(text, url)
}
return this.fallback ?? defaultFallback
}
Expand Down
10 changes: 10 additions & 0 deletions packages/cli-kit/src/private/node/hyperlink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Wraps `text` in an OSC-8 terminal hyperlink escape sequence pointing at `url`.
*
* See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda for the
* OSC-8 spec. The terminal must support hyperlinks for this to render as a link;
* callers should gate on `supports-hyperlinks` before using it.
*/
export function osc8Link(text: string, url: string): string {
return `\x1b]8;;${url}\x07${text}\x1b]8;;\x07`
}
4 changes: 2 additions & 2 deletions packages/cli-kit/src/private/node/ui/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {LinksContext, ContextValue as LinksContextValue} from '../contexts/LinksContext.js'
import {osc8Link} from '../../hyperlink.js'
import {Text} from 'ink'
import React, {FunctionComponent, useContext} from 'react'
import ansiEscapes from 'ansi-escapes'
import supportsHyperlinks from 'supports-hyperlinks'
import chalk from 'chalk'

Expand All @@ -27,7 +27,7 @@ function link(label: string | undefined, url: string, linksContext: LinksContext
return label ? `${label} [${linkId}]` : `[${linkId}]`
}

return ansiEscapes.link(label ?? url, url)
return osc8Link(label ?? url, url)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import React, {FunctionComponent, useRef} from 'react'

vi.mock('supports-hyperlinks')

// Matches the on-the-wire OSC 8 sequence emitted by `ansiEscapes.link`,
// which is what `<Link>` ultimately renders when the terminal supports
// hyperlinks. Format: `ESC ] 8 ; ; URL BEL TEXT ESC ] 8 ; ; BEL`.
// Matches the on-the-wire OSC 8 sequence emitted by `osc8Link`, which is what
// `<Link>` ultimately renders when the terminal supports hyperlinks.
// Format: `ESC ] 8 ; ; URL BEL TEXT ESC ] 8 ; ; BEL`.
function asOsc8Link(url: string, label?: string) {
return `\u001b]8;;${url}\u0007${label ?? url}\u001b]8;;\u0007`
}
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading