source dump of claude code
at main 57 lines 1.6 kB view raw
1import supportsHyperlinksLib from 'supports-hyperlinks' 2 3// Additional terminals that support OSC 8 hyperlinks but aren't detected by supports-hyperlinks. 4// Checked against both TERM_PROGRAM and LC_TERMINAL (the latter is preserved inside tmux). 5export const ADDITIONAL_HYPERLINK_TERMINALS = [ 6 'ghostty', 7 'Hyper', 8 'kitty', 9 'alacritty', 10 'iTerm.app', 11 'iTerm2', 12] 13 14type EnvLike = Record<string, string | undefined> 15 16type SupportsHyperlinksOptions = { 17 env?: EnvLike 18 stdoutSupported?: boolean 19} 20 21/** 22 * Returns whether stdout supports OSC 8 hyperlinks. 23 * Extends the supports-hyperlinks library with additional terminal detection. 24 * @param options Optional overrides for testing (env, stdoutSupported) 25 */ 26export function supportsHyperlinks( 27 options?: SupportsHyperlinksOptions, 28): boolean { 29 const stdoutSupported = 30 options?.stdoutSupported ?? supportsHyperlinksLib.stdout 31 if (stdoutSupported) { 32 return true 33 } 34 35 const env = options?.env ?? process.env 36 37 // Check for additional terminals not detected by supports-hyperlinks 38 const termProgram = env['TERM_PROGRAM'] 39 if (termProgram && ADDITIONAL_HYPERLINK_TERMINALS.includes(termProgram)) { 40 return true 41 } 42 43 // LC_TERMINAL is set by some terminals (e.g. iTerm2) and preserved inside tmux, 44 // where TERM_PROGRAM is overwritten to 'tmux'. 45 const lcTerminal = env['LC_TERMINAL'] 46 if (lcTerminal && ADDITIONAL_HYPERLINK_TERMINALS.includes(lcTerminal)) { 47 return true 48 } 49 50 // Kitty sets TERM=xterm-kitty 51 const term = env['TERM'] 52 if (term?.includes('kitty')) { 53 return true 54 } 55 56 return false 57}