first commit

This commit is contained in:
H
2026-04-03 13:01:19 +08:00
commit 538eced414
2575 changed files with 645911 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
import supportsHyperlinksLib from 'supports-hyperlinks'
// 支持 OSC 8 超链接但不在 supports-hyperlinks 检测范围内的额外终端。
// 针对 TERM_PROGRAM 和 LC_TERMINAL后者在 tmux 内保留)进行检查。
export const ADDITIONAL_HYPERLINK_TERMINALS = [
'ghostty',
'Hyper',
'kitty',
'alacritty',
'iTerm.app',
'iTerm2',
]
type EnvLike = Record<string, string | undefined>
type SupportsHyperlinksOptions = {
env?: EnvLike
stdoutSupported?: boolean
}
/**
* 返回 stdout 是否支持 OSC 8 超链接。
* 使用额外的终端检测扩展 supports-hyperlinks 库。
* @param options 可选的测试覆盖env, stdoutSupported
*/
export function supportsHyperlinks(
options?: SupportsHyperlinksOptions,
): boolean {
const stdoutSupported =
options?.stdoutSupported ?? supportsHyperlinksLib.stdout
if (stdoutSupported) {
return true
}
const env = options?.env ?? process.env
// 检查 supports-hyperlinks 未检测到的额外终端
const termProgram = env['TERM_PROGRAM']
if (termProgram && ADDITIONAL_HYPERLINK_TERMINALS.includes(termProgram)) {
return true
}
// LC_TERMINAL 由某些终端设置(例如 iTerm2并在 tmux 内保留,
// TERM_PROGRAM 被覆盖为 'tmux'。
const lcTerminal = env['LC_TERMINAL']
if (lcTerminal && ADDITIONAL_HYPERLINK_TERMINALS.includes(lcTerminal)) {
return true
}
// Kitty 设置 TERM=xterm-kitty
const term = env['TERM']
if (term?.includes('kitty')) {
return true
}
return false
}