Skip to content

Commit 3300fd4

Browse files
committed
wip: github links in stacks
1 parent 6775338 commit 3300fd4

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/ui/cli/Error.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTester } from '../TesterContext'
44
import { useSubscribers } from './useSubscribers'
55
import { Text } from 'ink'
66
import { Block, Line } from './Blocks'
7+
import { Link } from './Link'
78

89
export function StackEntryText({
910
entry,
@@ -16,7 +17,11 @@ export function StackEntryText({
1617
], [entry])
1718
tester.resolveErrorStackEntry(entry)
1819

19-
return <Text color="redBright" dimColor>at {String(entry)}</Text>
20+
const {url} = entry.resolved.get()
21+
22+
return url
23+
? <Link url={url}>{`at String(entry)`}</Link>
24+
: <Text color="redBright" dimColor>at {String(entry)}</Text>
2025
}
2126

2227
export function XErrorComponent({

src/ui/cli/Link.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import { Text, TextProps } from 'ink'
3+
4+
export function Link({
5+
children,
6+
url,
7+
...others
8+
}: TextProps & {
9+
children: string
10+
url: string
11+
}) {
12+
return <Text {...others}>{ttyHyperlink(url, children)}</Text>
13+
}
14+
15+
export function ttyHyperlink(
16+
url: string,
17+
text: string,
18+
) {
19+
return [
20+
OSC, '8;',
21+
'', // params
22+
';',
23+
url,
24+
BEL,
25+
text,
26+
OSC, '8;;',
27+
BEL,
28+
].join('')
29+
}
30+
31+
const OSC = '\u001B]'
32+
const BEL = '\u0007'

0 commit comments

Comments
 (0)