Răsfoiți Sursa

fix(tui): add macOS system appearance detection for Terminal.app

Terminal.app doesn't set $COLORFGBG. Fall back to macOS
AppleInterfaceStyle via execSync. All colors remain hex (no
16-color ANSI names that caused Terminal.app crashes).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fanghanjun 7 luni în urmă
părinte
comite
8967967418
1 a modificat fișierele cu 17 adăugiri și 1 ștergeri
  1. 17 1
      packages/cli/src/tui/theme.ts

+ 17 - 1
packages/cli/src/tui/theme.ts

@@ -1,9 +1,15 @@
 /** Whether the terminal is macOS Terminal.app. */
 export const isAppleTerminal = process.env.TERM_PROGRAM === "Apple_Terminal";
 
+import { execSync } from "node:child_process";
+
 type TerminalTheme = "dark" | "light";
 
-/** Detect via $COLORFGBG (set by iTerm2, rxvt, etc.). Default: dark. */
+/**
+ * 1. $COLORFGBG (iTerm2, rxvt)
+ * 2. macOS AppleInterfaceStyle (Terminal.app doesn't set COLORFGBG)
+ * 3. Default: dark
+ */
 function detectTerminalTheme(): TerminalTheme {
   const raw = process.env.COLORFGBG;
   if (raw) {
@@ -13,6 +19,16 @@ function detectTerminalTheme(): TerminalTheme {
       return bg <= 6 || bg === 8 ? "dark" : "light";
     }
   }
+  if (process.platform === "darwin") {
+    try {
+      const result = execSync("defaults read -g AppleInterfaceStyle", {
+        encoding: "utf8", timeout: 500, stdio: ["pipe", "pipe", "pipe"],
+      }).trim();
+      return result === "Dark" ? "dark" : "light";
+    } catch {
+      return "light";
+    }
+  }
   return "dark";
 }