rmux-core 0.10.0

Core session, pane, layout, format, hook, and buffer model for the RMUX terminal multiplexer.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
use super::*;

#[test]
fn known_options_do_not_cross_global_roots_during_resolve() {
    let mut store = OptionStore::new();
    let alpha = session_name("alpha");

    // Set a session-scoped option at server_global scope (which would not normally happen
    // via set validation, but let's test the resolve chain directly).
    // Instead, set status at session_global and verify it does NOT appear
    // when resolving a server-scoped option context.
    store
        .set(
            ScopeSelector::Global,
            OptionName::Status,
            "off".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("set succeeds");

    // status is session-scoped, resolve with no session should still find default "on"
    // because server context only looks at server_global.
    assert_eq!(store.resolve(None, OptionName::Status), Some("on"));

    // But resolve with a session should find "off" from session_global.
    assert_eq!(store.resolve(Some(&alpha), OptionName::Status), Some("off"));
}

#[cfg(unix)]
#[test]
fn unix_default_shell_starts_empty_for_runtime_resolution() {
    let store = OptionStore::new();

    assert_eq!(store.resolve(None, OptionName::DefaultShell), Some(""));
}

#[test]
fn tmux37_default_option_surface_matches_pinned_oracle() {
    let store = OptionStore::new();

    assert_eq!(store.resolve(None, OptionName::EscapeTime), Some("10"));
    assert_eq!(
        store.resolve(None, OptionName::TerminalOverrides),
        Some("linux*:AX@")
    );
    assert_eq!(
        store.resolve(None, OptionName::UpdateEnvironment),
        Some(
            "DISPLAY KRB5CCNAME MSYSTEM SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WAYLAND_DISPLAY WINDOWID XAUTHORITY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE"
        )
    );
    assert_eq!(
        store.resolve(None, OptionName::ModeStyle),
        Some("noattr,bg=yellow,fg=black")
    );
}

#[test]
fn notification_effects_are_reported_for_known_options() {
    let mut store = OptionStore::new();

    let outcome = store
        .set(
            ScopeSelector::Global,
            OptionName::Status,
            "off".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("set succeeds");

    assert_eq!(outcome.name, "status");
    assert_eq!(outcome.known_option, Some(OptionName::Status));
    assert_eq!(outcome.notifications.len(), 1);
    assert!(!outcome.notifications[0].effects.is_empty());
}

#[test]
fn notification_effects_for_user_options_default_to_pane_style() {
    let mut store = OptionStore::new();

    let outcome = store
        .set_by_name(
            OptionScopeSelector::SessionGlobal,
            "@theme",
            Some("dark".to_owned()),
            SetOptionMode::Replace,
            false,
            false,
            false,
        )
        .expect("user option set succeeds");

    assert_eq!(outcome.name, "@theme");
    assert_eq!(outcome.known_option, None);
    assert_eq!(outcome.notifications.len(), 1);
}

#[test]
fn default_size_rejects_empty_width_or_height() {
    let mut store = OptionStore::new();

    for invalid in ["x24", "80x", "x", "x0", "0x"] {
        let error = store
            .set(
                ScopeSelector::Session(session_name("alpha")),
                OptionName::DefaultSize,
                invalid.to_owned(),
                SetOptionMode::Replace,
            )
            .expect_err(&format!("'{invalid}' must fail"));
        assert_eq!(
            error,
            RmuxError::InvalidSetOption(format!("value is invalid: {invalid}"))
        );
    }

    // Valid forms still pass.
    store
        .set(
            ScopeSelector::Session(session_name("alpha")),
            OptionName::DefaultSize,
            "0x0".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("0x0 is valid");
    store
        .set(
            ScopeSelector::Session(session_name("alpha")),
            OptionName::DefaultSize,
            "200x50".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("200x50 is valid");
}

#[test]
fn append_on_choice_type_behaves_like_replace() {
    let mut store = OptionStore::new();

    store
        .set(
            ScopeSelector::Global,
            OptionName::StatusJustify,
            "centre".to_owned(),
            SetOptionMode::Append,
        )
        .expect("choice append behaves like set");

    assert_eq!(
        store.global_value(OptionName::StatusJustify),
        Some("centre")
    );
}

#[test]
fn invalid_choice_value_uses_tmux_error_text() {
    let mut store = OptionStore::new();

    let error = store
        .set(
            ScopeSelector::Global,
            OptionName::Status,
            "maybe".to_owned(),
            SetOptionMode::Replace,
        )
        .expect_err("invalid choice must fail");

    assert_eq!(
        error,
        RmuxError::InvalidSetOption("unknown value: maybe".to_owned())
    );
}

#[test]
fn explicit_empty_choice_value_is_invalid_like_tmux() {
    let mut store = OptionStore::new();

    let error = store
        .set_by_name(
            OptionScopeSelector::WindowGlobal,
            "mode-keys",
            Some(String::new()),
            SetOptionMode::Replace,
            false,
            false,
            false,
        )
        .expect_err("explicit empty choice value must fail");

    assert_eq!(
        error,
        RmuxError::InvalidSetOption("unknown value: ".to_owned())
    );
}

#[test]
fn invalid_flag_value_uses_tmux_error_text() {
    let mut store = OptionStore::new();

    let error = store
        .set_by_name(
            OptionScopeSelector::WindowGlobal,
            "automatic-rename",
            Some("false".to_owned()),
            SetOptionMode::Replace,
            false,
            false,
            false,
        )
        .expect_err("invalid flag value must fail");

    assert_eq!(
        error,
        RmuxError::InvalidSetOption("bad value: false".to_owned())
    );
}

#[test]
fn append_on_number_type_behaves_like_replace() {
    let mut store = OptionStore::new();

    store
        .set(
            ScopeSelector::Global,
            OptionName::HistoryLimit,
            "100".to_owned(),
            SetOptionMode::Append,
        )
        .expect("number append behaves like set");

    assert_eq!(store.global_value(OptionName::HistoryLimit), Some("100"));
}

#[test]
fn invalid_number_values_use_tmux_error_text() {
    let mut store = OptionStore::new();

    let too_small = store
        .set(
            ScopeSelector::Global,
            OptionName::HistoryLimit,
            "-5".to_owned(),
            SetOptionMode::Replace,
        )
        .expect_err("negative history-limit must fail");
    assert_eq!(
        too_small,
        RmuxError::InvalidSetOption("value is too small: -5".to_owned())
    );

    let invalid = store
        .set(
            ScopeSelector::Global,
            OptionName::DisplayTime,
            "abc".to_owned(),
            SetOptionMode::Replace,
        )
        .expect_err("non-numeric display-time must fail");
    assert_eq!(
        invalid,
        RmuxError::InvalidSetOption("value is invalid: abc".to_owned())
    );

    for option in [
        OptionName::BaseIndex,
        OptionName::StatusInterval,
        OptionName::RepeatTime,
        OptionName::MessageLimit,
    ] {
        let too_large = store
            .set(
                ScopeSelector::Global,
                option,
                "2147483648".to_owned(),
                SetOptionMode::Replace,
            )
            .expect_err("numbers above INT_MAX must fail");
        assert_eq!(
            too_large,
            RmuxError::InvalidSetOption("value is too large: 2147483648".to_owned())
        );

        store
            .set(
                ScopeSelector::Global,
                option,
                "2147483647".to_owned(),
                SetOptionMode::Replace,
            )
            .expect("INT_MAX itself is accepted");
    }
}

#[test]
fn unset_pane_overrides_at_non_window_scope_acts_like_plain_unset() {
    // Oracle probe 2026-07-09: tmux `set -U` at a non-window scope behaves
    // exactly like -u there and leaves pane overrides untouched.
    let mut store = OptionStore::new();
    let alpha = session_name("alpha");
    let pane = PaneTarget::with_window(alpha.clone(), 1, 0);

    store
        .set(
            ScopeSelector::Global,
            OptionName::WindowStyle,
            "fg=colour7".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("global set succeeds");
    store
        .set(
            ScopeSelector::Pane(pane.clone()),
            OptionName::WindowStyle,
            "fg=colour8".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("pane set succeeds");

    store
        .set_by_name(
            OptionScopeSelector::SessionGlobal,
            "window-style",
            None,
            SetOptionMode::Replace,
            false,
            true,
            true,
        )
        .expect("-U at session scope acts like -u");

    assert_eq!(
        store.pane_value(&pane, OptionName::WindowStyle),
        Some("fg=colour8"),
        "-U at a non-window scope must not clear pane overrides"
    );
}

#[test]
fn status_format_array_default_resolves_tmux_entries_in_snapshot() {
    let store = OptionStore::new();
    let alpha = session_name("alpha");

    // resolve() returns Option<&str> which cannot handle DefaultValue::Array,
    // but resolved() (the snapshot method) must fall back to default_value_as_string.
    let snapshot = store.resolved(&alpha);
    let value = snapshot
        .get(&OptionName::StatusFormat)
        .expect("status-format must be in snapshot");
    assert!(
        value.contains("#[align=left range=left"),
        "missing primary status line entry"
    );
    assert!(value.contains("#{P:"), "missing pane status-format entry");
    assert!(
        value.contains("#{S:"),
        "missing session status-format entry"
    );
}

#[cfg(windows)]
#[test]
fn status_right_default_uses_host_short_on_windows() {
    let store = OptionStore::new();
    let alpha = session_name("alpha");
    let value = store
        .resolve(Some(&alpha), OptionName::StatusRight)
        .expect("status-right default resolves");

    assert!(
        value.contains("#{=21:host_short}"),
        "status-right should show the host name, got {value:?}"
    );
    assert!(
        !value.contains("pane_title"),
        "status-right must not depend on pane title updates, got {value:?}"
    );
}

#[cfg(not(windows))]
#[test]
fn status_right_default_uses_pane_title_on_unix_like_platforms() {
    let store = OptionStore::new();
    let alpha = session_name("alpha");
    let value = store
        .resolve(Some(&alpha), OptionName::StatusRight)
        .expect("status-right default resolves");

    assert!(
        value.contains("#{=21:pane_title}"),
        "status-right should match tmux 3.7b pane-title default, got {value:?}"
    );
    assert!(
        !value.contains("host_short"),
        "status-right must not use host name on non-Windows, got {value:?}"
    );
}

#[test]
fn empty_array_default_resolves_to_empty_string() {
    let store = OptionStore::new();
    let alpha = session_name("alpha");

    // pane-colours has an empty scalar default and is an array option.
    let value = store.resolve_for_window(&alpha, 0, OptionName::PaneColours);
    assert_eq!(value, Some(""));
}

#[test]
fn colour_alias_prefix_does_not_match_wrong_canonical_name() {
    // "cursor-col" should unambiguously resolve to "cursor-colour"
    // (via its "cursor-color" alias), not conflict with anything else.
    let query = resolve_option_name("cursor-col").expect("prefix resolves");
    assert_eq!(query.canonical_name(), "cursor-colour");
}

#[test]
fn frozen_registry_scope_counts_match_tmux_partitioning() {
    let metadata = registry::registry();
    let server_count = metadata
        .iter()
        .filter(|entry| entry.scope_mask() == registry::SCOPE_SERVER)
        .count();
    let session_count = metadata
        .iter()
        .filter(|entry| entry.scope_mask() == registry::SCOPE_SESSION)
        .count();
    let window_only_count = metadata
        .iter()
        .filter(|entry| entry.scope_mask() == registry::SCOPE_WINDOW)
        .count();
    let window_pane_count = metadata
        .iter()
        .filter(|entry| entry.scope_mask() == (registry::SCOPE_WINDOW | registry::SCOPE_PANE))
        .count();

    // tmux 3.7b frozen: 25 server, 54 session, 70 window (52 window-only + 18 window|pane)
    assert_eq!(server_count, 25, "server options");
    assert_eq!(session_count, 54, "session options");
    assert_eq!(
        window_only_count + window_pane_count,
        70,
        "window options total"
    );
    assert_eq!(window_pane_count, 18, "window|pane dual-scope options");
}