Explorar o código

fix(tui): add light/dark theme via COLORFGBG without execSync

Detect terminal background via $COLORFGBG (env var only, no child
process). Use darker hex colors for light backgrounds so text is
readable. No 16-color ANSI names — all hex like the main branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fanghanjun hai 7 meses
pai
achega
34182fb036
Modificáronse 1 ficheiros con 26 adicións e 12 borrados
  1. 26 12
      packages/cli/src/tui/theme.ts

+ 26 - 12
packages/cli/src/tui/theme.ts

@@ -1,17 +1,31 @@
 /** Whether the terminal is macOS Terminal.app. */
 export const isAppleTerminal = process.env.TERM_PROGRAM === "Apple_Terminal";
 
-export const WARM_ACCENT = "#c88a56";
-export const WARM_MUTED = "#8f8374";
-export const WARM_REPLY = "#f0e6d8";
-export const WARM_BORDER = "#6b6156";
+type TerminalTheme = "dark" | "light";
 
-// Semantic status colors
-export const STATUS_SUCCESS = "#7ec87e";
-export const STATUS_ERROR = "#e06060";
-export const STATUS_ACTIVE = "#d4a76a";
-export const STATUS_IDLE = "#7a7268";
+/** Detect via $COLORFGBG (set by iTerm2, rxvt, etc.). Default: dark. */
+function detectTerminalTheme(): TerminalTheme {
+  const raw = process.env.COLORFGBG;
+  if (raw) {
+    const parts = raw.split(";");
+    const bg = Number(parts[parts.length - 1]);
+    if (!Number.isNaN(bg)) {
+      return bg <= 6 || bg === 8 ? "dark" : "light";
+    }
+  }
+  return "dark";
+}
 
-// Role colors
-export const ROLE_USER = "#a8c4d4";
-export const ROLE_SYSTEM = "#b8a8d0";
+const isDark = detectTerminalTheme() === "dark";
+
+// Dark theme (original main-branch values)
+export const WARM_ACCENT = isDark ? "#c88a56" : "#8b5e3c";
+export const WARM_MUTED = isDark ? "#8f8374" : "#7a6e62";
+export const WARM_REPLY = isDark ? "#f0e6d8" : "#2a4a6a";
+export const WARM_BORDER = isDark ? "#6b6156" : "#b0a898";
+export const STATUS_SUCCESS = isDark ? "#7ec87e" : "#2e7d32";
+export const STATUS_ERROR = isDark ? "#e06060" : "#c62828";
+export const STATUS_ACTIVE = isDark ? "#d4a76a" : "#a06020";
+export const STATUS_IDLE = isDark ? "#7a7268" : "#908478";
+export const ROLE_USER = isDark ? "#a8c4d4" : "#3a6a8a";
+export const ROLE_SYSTEM = isDark ? "#b8a8d0" : "#5c4a80";