MCPcopy Create free account
hub / github.com/Noumena-Network/code / probeTmuxControlModeSync

Function probeTmuxControlModeSync

src/utils/fullscreen.ts:57–87  ·  view source on GitHub ↗

* Sync one-shot probe: asks tmux directly whether this client is in control * mode via `#{client_control_mode}`. Runs on first isTmuxControlMode() call * when the env heuristic can't decide; result is cached. * * Sync (spawnSync) because the answer gates whether we enter fullscreen — an * async

()

Source from the content-addressed store, hash-verified

55 * query whatever tmux server happens to be running rather than our client.
56 */
57function probeTmuxControlModeSync(): void {
58 // Seed cache with heuristic result so early returns below don't leave it
59 // undefined — isTmuxControlMode() is called 15+ times per render, and an
60 // undefined cache would re-enter this function (re-spawning tmux in the
61 // failure case) on every call.
62 tmuxControlModeProbed = isTmuxControlModeEnvHeuristic()
63 if (tmuxControlModeProbed) return
64 if (!process.env.TMUX) return
65 // Only probe when iTerm might be involved: TERM_PROGRAM is iTerm.app
66 // (covered above) or not set (SSH often doesn't propagate it). When
67 // TERM_PROGRAM is explicitly a non-iTerm terminal, skip — tmux -CC is
68 // an iTerm-only feature, so the subprocess would be wasted.
69 if (process.env.TERM_PROGRAM) return
70 let result
71 try {
72 result = spawnSync(
73 'tmux',
74 ['display-message', '-p', '#{client_control_mode}'],
75 { encoding: 'utf8', timeout: 2000 },
76 )
77 } catch {
78 // spawnSync can throw on some platforms (e.g. ENOENT on Windows if tmux
79 // is absent and the runtime surfaces it as an exception rather than in
80 // result.error). Treat the same as a non-zero exit.
81 return
82 }
83 // Non-zero exit / spawn error: tmux too old (format var added in 2.4) or
84 // unavailable. Keep the heuristic result cached.
85 if (result.status !== 0) return
86 tmuxControlModeProbed = result.stdout.trim() === '1'
87}
88
89/**
90 * True when running under `tmux -CC` (iTerm2 integration mode).

Callers 1

isTmuxControlModeFunction · 0.85

Calls 1

Tested by

no test coverage detected