feat: Detect background color
Summary
We need to detect the true terminal background color in order to properly blend between theme colors and the terminal background to simulate opacity. Detecting the terminal background color also helps ensure users who do not open the theme dialog get an acceptable default theme.
This also enables us to warn on startup for users who have a theme that is incompatible with their background color.
Details
Turns out that there is a standard terminal API for detecting the terminal background color which wile not universally support is much more widely supported than I would have expected.
-
Automatic Theme Detection: The application now attempts to detect the terminal's background color at startup using an OSC 11 query, providing a more tailored initial experience.
-
Intelligent Default Theme Selection: If a user has not explicitly set a theme, the application will automatically select a light or dark theme that best matches the detected terminal background, improving visual compatibility out-of-the-box.
-
Enhanced Theme Dialog: The theme selection dialog has been updated to provide visual cues, indicating which themes are compatible with the terminal's background and highlighting exact background color matches. Incompatible themes are also sorted lower for better user guidance.
-
Warning for Mismatched Themes: A warning is now displayed if the currently active theme's light/dark type does not match the detected terminal's background, prompting the user to consider changing themes for optimal display.
-
New Terminal Color Detection Utility: A new utility file,
terminalColorDetector.ts, has been added to handle the logic for querying and parsing the terminal's background color. As a bonus it also queries for the terminal name. Logic has been simplified with smarter timeout behavior using the DEVICE_ATTRIBUTES_QUERY ('\x1b[c') to quickly terminate as soon as we detect the terminal is done responding to our queries. -
Terminal capability in bug reports: Bug reports now list the terminal users are using as well as whether it was detected as supporting the kitty protocol and the background color. This should reduce back and forth asking clarifying questions on UX related bugs.
Related Issues
How to Validate
Test your favorite terminal and open the the debug console to see what background color was detected.
Example:
Example mismatched theme error:
Remove the background color from your ~/.gemini/settings.json and verify that Gemini picks an acceptable theme at startup. For fun, notice that if you happen to run the shades of purple theme in VScode or Antigravity, Gemini will autodetect that your background color exactly matches that theme and will set you to Gemini CLIs shades of purple theme.
This is a step towards fixing https://github.com/google-gemini/gemini-cli/issues/14385 as this allows us to give the input prompt what appears to be a semi transparent background.
Size Change: +9.67 kB (+0.04%)
Total Size: 22 MB
| Filename | Size | Change |
|---|---|---|
./bundle/gemini.js |
22 MB | +9.67 kB (+0.04%) |
ℹ️ View Unchanged
| Filename | Size |
|---|---|
./bundle/sandbox-macos-permissive-closed.sb |
1.03 kB |
./bundle/sandbox-macos-permissive-open.sb |
890 B |
./bundle/sandbox-macos-permissive-proxied.sb |
1.31 kB |
./bundle/sandbox-macos-restrictive-closed.sb |
3.29 kB |
./bundle/sandbox-macos-restrictive-open.sb |
3.36 kB |
./bundle/sandbox-macos-restrictive-proxied.sb |
3.56 kB |
It feels like we added a lot of code to gemini.tsx. Can this be moved elsewhere? Same for AppContainer.tsx
moved extra logic out of gemini.tsx https://github.com/google-gemini/gemini-cli/pull/15132/changes/69dc68a5e526814bb7be7d8bf228f351f6b23a5f
Not sure I follow for AppContainer. Its delta is only 4 lines and part of that is just renames. If that is a concern can work on refactoring it in a follow up.
moved the telemetry test fix to a separate branch. will send out a review for it shortly.