Skip to content

feat: add cmux theme picker live preview hooks#42

Open
xiaocang wants to merge 1 commit into
manaflow-ai:mainfrom
xiaocang:feat/cmux-theme-picker
Open

feat: add cmux theme picker live preview hooks#42
xiaocang wants to merge 1 commit into
manaflow-ai:mainfrom
xiaocang:feat/cmux-theme-picker

Conversation

@xiaocang
Copy link
Copy Markdown

@xiaocang xiaocang commented Apr 16, 2026

Summary

  • When CMUX_THEME_PICKER_* environment variables are set, the +list-themes TUI writes theme choices to a config file and sends an NSDistributedNotification so the cmux app reloads themes in real-time
  • Without those env vars, behavior is completely unchanged from upstream
  • Supports independent light/dark theme targeting via CMUX_THEME_PICKER_TARGET

Environment variables

  • CMUX_THEME_PICKER_CONFIG — path to the config file to write theme overrides
  • CMUX_THEME_PICKER_BUNDLE_ID — bundle ID for the notification (default: com.cmuxterm.app)
  • CMUX_THEME_PICKER_INITIAL_LIGHT / CMUX_THEME_PICKER_INITIAL_DARK — current theme names for initial selection
  • CMUX_THEME_PICKER_TARGETboth, light, or dark

Changes from upstream list_themes.zig

  • New CmuxThemePicker struct loaded from env vars
  • Live preview: writes managed theme block to config file on selection change
  • NSDistributedNotification to signal cmux to reload config
  • Footer bar showing current preview state and keybinds
  • t key to cycle target mode (both/light/dark)
  • Enter applies and exits; q/Esc cancels and restores original config
  • Consolidated preview sync in render loop (single call with dedup, not per-action)

Test plan

  • Run ghostty +list-themes without env vars — behavior identical to upstream
  • Run with CMUX_THEME_PICKER_CONFIG=/tmp/test-theme.conf ghostty +list-themes — verify live preview writes config file on navigation
  • Verify cancel (q/Esc) restores original config file contents
  • Verify apply (Enter) keeps the selected theme in config
  • Verify t key cycles target mode in footer bar

🤖 Generated with Claude Code


Summary by cubic

Adds live cmux theme preview to ghostty +list-themes. When CMUX_THEME_PICKER_* vars are set, the picker writes a managed theme block to a config file and sends a macOS distributed notification so cmux reloads instantly. Unset vars keep upstream behavior.

  • New Features

    • Env-driven cmux mode (CmuxThemePicker): writes a managed block to CMUX_THEME_PICKER_CONFIG and posts com.cmuxterm.themes.reload-config via NSDistributedNotificationCenter (bundle from CMUX_THEME_PICKER_BUNDLE_ID, default com.cmuxterm.app).
    • Target modes both/light/dark via CMUX_THEME_PICKER_TARGET; press t to cycle. Enter applies and exits; q/Esc cancels and restores the original file. Initial selection can be seeded by CMUX_THEME_PICKER_INITIAL_LIGHT/CMUX_THEME_PICKER_INITIAL_DARK.
    • Footer shows live preview state; selection sync is deduped in the render loop. Title reflects cmux mode. Notifications are macOS-only; all behavior is unchanged without the env vars.
    • Cancel fully restores the original config; apply keeps the selected theme(s).
  • Migration

    • Set CMUX_THEME_PICKER_CONFIG=/path/to/cmux.conf.
    • Optional: CMUX_THEME_PICKER_BUNDLE_ID, CMUX_THEME_PICKER_INITIAL_LIGHT, CMUX_THEME_PICKER_INITIAL_DARK, CMUX_THEME_PICKER_TARGET=both|light|dark.
    • Run ghostty +list-themes; use t to change target, Enter to apply, q/Esc to cancel.

Written for commit 45c4266. Summary will update on new commits.

When CMUX_THEME_PICKER_* environment variables are set, the theme
picker writes theme choices to a config file and sends an
NSDistributedNotification so the cmux app reloads themes in real-time.
Without those env vars, behavior is unchanged from upstream.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Warning

Rate limit exceeded

@xiaocang has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 50 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 50 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 145bf05b-060b-4cdd-9900-0948ccbe91c7

📥 Commits

Reviewing files that changed from the base of the PR and between 3b684a0 and 45c4266.

📒 Files selected for processing (1)
  • src/cli/list_themes.zig
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/cli/list_themes.zig">

<violation number="1" location="src/cli/list_themes.zig:718">
P1: Unused local constant `cmux` in new code can cause Zig compile failure.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/cli/list_themes.zig
}

fn applyCmuxSelectionForCurrentTheme(self: *Preview) !void {
const cmux = self.cmux orelse return;
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Unused local constant cmux in new code can cause Zig compile failure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/cli/list_themes.zig, line 718:

<comment>Unused local constant `cmux` in new code can cause Zig compile failure.</comment>

<file context>
@@ -411,6 +700,72 @@ const Preview = struct {
+    }
+
+    fn applyCmuxSelectionForCurrentTheme(self: *Preview) !void {
+        const cmux = self.cmux orelse return;
+        if (self.filtered.items.len == 0) return;
+
</file context>
Suggested change
const cmux = self.cmux orelse return;
if (self.cmux == null) return;
Fix with Cubic

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR adds an opt-in live theme preview mechanism to +list-themes that writes a managed config block and fires an NSDistributedNotification when the relevant CMUX_THEME_PICKER_* env vars are set. The guard-pattern approach cleanly preserves upstream behavior.

  • P0 compile error: const cmux = self.cmux orelse return; in applyCmuxSelectionForCurrentTheme is an unused local constant — Zig rejects this at compile time, breaking +list-themes for all users.
  • P1: writeAbsoluteFile uses std.fs.makeDirAbsolute (one directory level only), so any config path whose parent doesn't yet exist will silently fail on first use.
  • P1: The help-overlay loop reuses the raw captured_i index after skipping empty entries, leaving a visible blank row in cmux mode.

Confidence Score: 2/5

Not safe to merge — a compile error in the new code breaks +list-themes for all users.

The unused local constant cmux in applyCmuxSelectionForCurrentTheme is a Zig compile error that prevents the entire file from being compiled, regressing non-cmux users. Two additional P1 issues (non-recursive mkdir, help-screen row gap) also need fixing before this is production-ready.

src/cli/list_themes.zig — compile error on line 718, directory creation on line 324, help overlay loop on lines 1194-1196.

Important Files Changed

Filename Overview
src/cli/list_themes.zig Adds CmuxThemePicker struct, live config-file writes, NSDistributedNotification, and footer UI; has a compile-blocking unused-constant error, a single-level mkdir that breaks nested config paths, and a help-screen row-gap bug when cmux mode skips entries.

Sequence Diagram

sequenceDiagram
    participant User
    participant Preview as list_themes TUI
    participant FS as Config File
    participant NS as NSDistributedNotification
    participant cmux as cmux App

    User->>Preview: launch with CMUX_THEME_PICKER_CONFIG set
    Preview->>FS: readOptionalFile (capture original_contents)
    Preview->>Preview: CmuxThemePicker.load() — read env vars

    loop Render loop (every frame)
        User->>Preview: navigate (j/k/scroll)
        Preview->>Preview: applyCmuxSelectionForCurrentTheme()
        Preview->>Preview: syncCmuxPreview() — dedup check
        alt theme changed
            Preview->>FS: writeCmuxThemeOverride (managed block)
            Preview->>NS: postNotificationName:object:deliverImmediately:
            NS-->>cmux: com.cmuxterm.themes.reload-config
            cmux-->>User: live theme update
        end
        Preview->>User: draw TUI frame
    end

    alt User presses Enter (apply)
        Preview->>Preview: outcome = .apply, should_quit = true
        Note over FS: managed block stays in config
    else User presses q/Esc (cancel)
        Preview->>Preview: outcome = .cancel, should_quit = true
        Preview->>FS: restoreCmuxThemeOverride (original_contents)
        Preview->>NS: postNotificationName (reload)
        NS-->>cmux: revert to original theme
    end
Loading

Reviews (1): Last reviewed commit: "feat: add cmux theme picker helper hooks" | Re-trigger Greptile

Comment thread src/cli/list_themes.zig
}

fn applyCmuxSelectionForCurrentTheme(self: *Preview) !void {
const cmux = self.cmux orelse return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Unused local constant — compile error

const cmux = self.cmux orelse return; binds the unwrapped value but it is never referenced; self.cmux.? is used in the switch below instead. Zig treats unused local constants as a hard compile error ("pointless discard of local constant"), so this entire file will not compile, breaking +list-themes for all users regardless of whether the env vars are set.

Fix: use the bound cmux value in the switch body to eliminate the unused binding.

Suggested change
const cmux = self.cmux orelse return;
fn applyCmuxSelectionForCurrentTheme(self: *Preview) !void {
const cmux = self.cmux orelse return;
if (self.filtered.items.len == 0) return;
const theme = self.themes[self.filtered.items[self.current]].theme;
switch (cmux.target_mode) {

Comment thread src/cli/list_themes.zig
Comment on lines +323 to +328
if (std.fs.path.dirname(path)) |dir| {
std.fs.makeDirAbsolute(dir) catch |err| switch (err) {
error.PathAlreadyExists => {},
else => return err,
};
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Single-level directory creation will fail for nested paths

std.fs.makeDirAbsolute creates only one directory level. If the user-supplied CMUX_THEME_PICKER_CONFIG path sits under directories that do not exist yet (e.g. ~/.config/cmux/theme.conf when ~/.config/cmux/ is missing), this will propagate error.FileNotFound back to the caller and silently prevent live preview from working on first run.

Replace with std.fs.cwd().makePath(dir), which creates the full directory chain and is already idempotent for existing paths:

Suggested change
if (std.fs.path.dirname(path)) |dir| {
std.fs.makeDirAbsolute(dir) catch |err| switch (err) {
error.PathAlreadyExists => {},
else => return err,
};
}
if (std.fs.path.dirname(path)) |dir| {
try std.fs.cwd().makePath(dir);
}

Comment thread src/cli/list_themes.zig
Comment on lines 1194 to 1196
for (key_help, 0..) |help, captured_i| {
if (help.help.len == 0) continue;
const i: u16 = @intCast(captured_i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Help overlay has a blank row when entries are skipped

captured_i keeps incrementing for every element in key_help, including the ones that get continued. Because row_offset = i + 1 uses this raw index, any skipped entry leaves a blank row in the overlay. In cmux mode, the "w" entry (index 18) is skipped, so the rendered "t" entry appears one row too low and a visible gap is left above it.

Track a separate render counter to keep rows contiguous:

Suggested change
for (key_help, 0..) |help, captured_i| {
if (help.help.len == 0) continue;
const i: u16 = @intCast(captured_i);
var row: u16 = 0;
for (key_help) |help| {
if (help.help.len == 0) continue;
defer row += 1;

Then replace the three row_offset = i + 1 references below with row_offset = row + 1.

Comment thread src/cli/list_themes.zig
Comment on lines 572 to +576
pub fn run(self: *Preview) !void {
errdefer self.restoreCmuxOriginal() catch {};
defer if (self.outcome == .cancel) {
self.restoreCmuxOriginal() catch {};
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Double restore on error

When run() returns an error and outcome is still .cancel (the initial value), both the errdefer on line 573 and the defer on lines 574-576 fire, calling restoreCmuxOriginal twice. The second write is redundant. Consider removing the errdefer and relying solely on the defer, which already handles cancel correctly:

Suggested change
pub fn run(self: *Preview) !void {
errdefer self.restoreCmuxOriginal() catch {};
defer if (self.outcome == .cancel) {
self.restoreCmuxOriginal() catch {};
};
defer if (self.outcome == .cancel) {
self.restoreCmuxOriginal() catch {};
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant