Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)"

This reverts commit 88d4c3ba24.
This commit is contained in:
claude-code-best
2026-04-07 16:17:48 +08:00
parent 4e1e681a46
commit e5782e732c
645 changed files with 7312 additions and 1272 deletions

View File

@@ -0,0 +1,40 @@
/**
* Terminal dark/light mode detection.
*
* Detection is based on the terminal's actual background color (queried via
* OSC 11) rather than the OS appearance setting.
*
* Vendored from src/utils/systemTheme.ts for package independence.
*/
export type SystemTheme = 'dark' | 'light'
let cachedSystemTheme: SystemTheme | undefined
/**
* Detect theme from $COLORFGBG environment variable (set by some terminals).
*/
function detectFromColorFgBg(): SystemTheme | undefined {
const colorFgBg = process.env.COLORFGBG
if (!colorFgBg) return undefined
const parts = colorFgBg.split(';')
if (parts.length < 2) return undefined
const bg = parseInt(parts[parts.length - 1]!, 10)
// Standard ANSI color indices: 0-7 are dark, 8-15 are bright/light
if (isNaN(bg)) return undefined
return bg >= 8 ? 'light' : 'dark'
}
/**
* Get the current terminal theme. Cached after first detection.
*/
export function getSystemThemeName(): SystemTheme {
if (cachedSystemTheme === undefined) {
cachedSystemTheme = detectFromColorFgBg() ?? 'dark'
}
return cachedSystemTheme
}
export function setCachedSystemTheme(theme: SystemTheme): void {
cachedSystemTheme = theme
}