rmux-server 0.10.0

Tokio daemon and request dispatcher 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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
use super::{CursorScope, OuterTerminal, OuterTerminalContext};
use rmux_core::{OptionStore, Session};
use rmux_proto::{
    ClientTerminalContext, OptionName, ScopeSelector, SessionName, SetOptionMode, TerminalSize,
};

fn session_name(value: &str) -> SessionName {
    SessionName::new(value).expect("valid session name")
}

fn make_session() -> Session {
    Session::new(session_name("alpha"), TerminalSize { cols: 80, rows: 24 })
}

const MOUSE_ENABLE_SEQUENCE: &str = "\u{1b}[?1006h\u{1b}[?1000h\u{1b}[?1002h";
const MOUSE_DISABLE_SEQUENCE: &str = "\u{1b}[?1002l\u{1b}[?1000l\u{1b}[?1006l";

#[test]
fn terminal_features_match_globs_and_case_insensitive_feature_names() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalFeatures,
            "xterm-kitty*:ClIpBoArD:EXTKEYS".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-features append succeeds");

    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-kitty")]),
    );

    assert!(terminal.features_string().contains("clipboard"));
    assert!(terminal.features_string().contains("extkeys"));
}

#[test]
fn xterm_kitty_enables_kitty_graphics_feature() {
    let terminal = OuterTerminal::resolve(
        &OptionStore::default(),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-kitty")]),
    );

    assert!(terminal.supports_kitty_graphics());
    assert!(terminal.features_string().contains("kitty-graphics"));
}

#[test]
fn modern_kitty_graphics_terminals_enable_kitty_graphics_feature() {
    for context in [
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-ghostty")]),
        OuterTerminalContext::from_pairs(&[("TERM", "wezterm")]),
        OuterTerminalContext::from_pairs(&[
            ("TERM", "xterm-256color"),
            ("TERM_PROGRAM", "ghostty"),
        ]),
        OuterTerminalContext::from_pairs(&[
            ("TERM", "xterm-256color"),
            ("TERM_PROGRAM", "WezTerm"),
        ]),
    ] {
        let terminal = OuterTerminal::resolve(&OptionStore::default(), context);
        assert!(terminal.supports_kitty_graphics());
        assert!(terminal.features_string().contains("kitty-graphics"));
    }
}

#[test]
fn known_sixel_terminals_enable_sixel_feature() {
    for context in [
        OuterTerminalContext::from_pairs(&[("TERM", "mintty")]),
        OuterTerminalContext::from_pairs(&[("TERM", "foot")]),
        OuterTerminalContext::from_pairs(&[("TERM", "mlterm")]),
        OuterTerminalContext::from_pairs(&[
            ("TERM", "xterm-256color"),
            ("TERM_PROGRAM", "WezTerm"),
        ]),
    ] {
        let terminal = OuterTerminal::resolve(&OptionStore::default(), context);
        assert!(terminal.supports_sixel());
        assert!(terminal.features_string().contains("sixel"));
    }
}

#[test]
fn terminal_features_can_enable_sixel_for_other_terms() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalFeatures,
            "xterm*:sixel".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-features append succeeds");

    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    assert!(terminal.supports_sixel());
}

#[test]
fn terminal_overrides_apply_legacy_tc_xt_and_ax_flags() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalOverrides,
            "linux*:Tc:XT:AX@".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-overrides append succeeds");

    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "linux")]),
    );

    let features = terminal.features_string();
    assert!(features.contains("RGB"));
    assert!(features.contains("bpaste"));
    assert!(features.contains("focus"));
    assert!(features.contains("title"));
}

#[test]
fn attach_sequences_follow_focus_and_extended_key_options() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::FocusEvents,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("focus-events set succeeds");
    options
        .set(
            ScopeSelector::Global,
            OptionName::ExtendedKeys,
            "always".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("extended-keys set succeeds");
    options
        .set(
            ScopeSelector::Global,
            OptionName::Mouse,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("mouse set succeeds");

    let terminal = OuterTerminal::resolve_for_session(
        &options,
        Some(&session_name("alpha")),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color"), ("COLORTERM", "truecolor")]),
    );

    let start = String::from_utf8(terminal.attach_start_sequence()).expect("utf8");
    let stop = String::from_utf8(terminal.attach_stop_sequence()).expect("utf8");

    assert!(start.starts_with("\u{1b}[?1049h\u{1b}[22;0;0t\u{1b}[0m\u{1b}[?25l\u{1b}[H\u{1b}[2J"));
    assert!(start.contains("\u{1b}[22;0;0t"));
    assert!(start.contains("\u{1b}[?2004h"));
    assert!(start.contains("\u{1b}[?1006h"));
    assert!(start.contains("\u{1b}[?1002h"));
    assert!(start.contains("\u{1b}[?1000h"));
    assert!(start.contains(MOUSE_ENABLE_SEQUENCE));
    assert!(start.contains("\u{1b}[?1004h"));
    assert!(start.contains("\u{1b}[>4;2m"));
    assert!(stop.contains("\u{1b}[?2004l"));
    assert!(stop.contains("\u{1b}[?1000l"));
    assert!(stop.contains("\u{1b}[?1002l"));
    assert!(stop.contains("\u{1b}[?1006l"));
    assert!(stop.contains(MOUSE_DISABLE_SEQUENCE));
    assert!(stop.contains("\u{1b}[?1004l"));
    assert!(stop.contains("\u{1b}[>4m"));
    assert!(stop.ends_with("\u{1b}[?1049l\u{1b}[23;0;0t"));
}

#[test]
fn client_mouse_feature_enables_mouse_attach_sequences_when_mouse_option_is_on() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::Mouse,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("mouse set succeeds");

    let terminal = OuterTerminal::resolve_for_session(
        &options,
        Some(&session_name("alpha")),
        OuterTerminalContext::default().with_client_terminal(&ClientTerminalContext {
            terminal_features: vec!["mouse".to_owned()],
            utf8: true,
        }),
    );

    let start = String::from_utf8(terminal.attach_start_sequence()).expect("utf8");
    let stop = String::from_utf8(terminal.attach_stop_sequence()).expect("utf8");

    assert!(start.contains("\u{1b}[?1006h"));
    assert!(start.contains("\u{1b}[?1002h"));
    assert!(start.contains("\u{1b}[?1000h"));
    assert!(start.contains(MOUSE_ENABLE_SEQUENCE));
    assert!(stop.contains("\u{1b}[?1000l"));
    assert!(stop.contains("\u{1b}[?1002l"));
    assert!(stop.contains("\u{1b}[?1006l"));
    assert!(stop.contains(MOUSE_DISABLE_SEQUENCE));
}

#[test]
fn active_pane_mouse_tracking_enables_outer_mouse_with_mouse_option_off() {
    // Issue #93: tmux enables outer mouse reporting when the `mouse` option
    // is on OR the active pane's application requested a tracking mode, so
    // vim/htop over SSH must get mouse events with `mouse off`.
    let terminal = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        OuterTerminalContext::default().with_client_terminal(&ClientTerminalContext {
            terminal_features: vec!["mouse".to_owned()],
            utf8: true,
        }),
    )
    .with_active_pane_mouse_mode(rmux_core::input::mode::MODE_MOUSE_BUTTON);

    let start = String::from_utf8(terminal.attach_start_sequence()).expect("utf8");
    assert!(
        start.contains(MOUSE_ENABLE_SEQUENCE),
        "pane-driven tracking must enable outer mouse despite mouse=off"
    );
}

#[test]
fn without_option_or_pane_tracking_outer_mouse_stays_disabled() {
    let terminal = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        OuterTerminalContext::default().with_client_terminal(&ClientTerminalContext {
            terminal_features: vec!["mouse".to_owned()],
            utf8: true,
        }),
    )
    .with_active_pane_mouse_mode(0);

    let start = String::from_utf8(terminal.attach_start_sequence()).expect("utf8");
    assert!(
        !start.contains("\u{1b}[?1000h"),
        "no option and no pane tracking must not enable outer mouse"
    );
}

#[test]
fn transition_disables_outer_mouse_when_the_pane_stops_tracking() {
    let context = || {
        OuterTerminalContext::default().with_client_terminal(&ClientTerminalContext {
            terminal_features: vec!["mouse".to_owned()],
            utf8: true,
        })
    };
    let tracking = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        context(),
    )
    .with_active_pane_mouse_mode(rmux_core::input::mode::MODE_MOUSE_BUTTON);
    let idle = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        context(),
    )
    .with_active_pane_mouse_mode(0);

    let enable = String::from_utf8(tracking.transition_sequence_from(&idle)).expect("utf8");
    assert!(
        enable.contains(MOUSE_ENABLE_SEQUENCE),
        "pane starting to track must enable outer mouse on refresh"
    );
    let disable = String::from_utf8(idle.transition_sequence_from(&tracking)).expect("utf8");
    assert!(
        disable.contains(MOUSE_DISABLE_SEQUENCE),
        "pane resetting its tracking mode must disable outer mouse on refresh"
    );
}

#[test]
fn active_pane_all_motion_tracking_preserves_decset_1003() {
    let terminal = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        OuterTerminalContext::default().with_client_terminal(&ClientTerminalContext {
            terminal_features: vec!["mouse".to_owned()],
            utf8: true,
        }),
    )
    .with_active_pane_mouse_mode(rmux_core::input::mode::MODE_MOUSE_ALL);

    let start = String::from_utf8(terminal.attach_start_sequence()).expect("utf8");
    assert!(start.contains("\u{1b}[?1003h"));
    assert!(!start.contains("\u{1b}[?1002h"));

    let stop = String::from_utf8(terminal.attach_stop_sequence()).expect("utf8");
    assert!(stop.contains("\u{1b}[?1003l"));
}

#[test]
fn focus_follows_mouse_option_upgrades_mouse_tracking_to_all_motion() {
    let context = || {
        OuterTerminalContext::default().with_client_terminal(&ClientTerminalContext {
            terminal_features: vec!["mouse".to_owned()],
            utf8: true,
        })
    };
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::FocusFollowsMouse,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("focus-follows-mouse set succeeds");

    let mouse_off =
        OuterTerminal::resolve_for_session(&options, Some(&session_name("alpha")), context());
    let off_start = String::from_utf8(mouse_off.attach_start_sequence()).expect("utf8");
    assert!(!off_start.contains("\u{1b}[?1003h"));

    options
        .set(
            ScopeSelector::Global,
            OptionName::Mouse,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("mouse set succeeds");
    let mouse_on =
        OuterTerminal::resolve_for_session(&options, Some(&session_name("alpha")), context());
    let on_start = String::from_utf8(mouse_on.attach_start_sequence()).expect("utf8");
    assert!(on_start.contains("\u{1b}[?1003h"));
    assert!(!on_start.contains("\u{1b}[?1002h"));

    options
        .set(
            ScopeSelector::Global,
            OptionName::FocusFollowsMouse,
            "off".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("focus-follows-mouse unset succeeds");
    let button_tracking =
        OuterTerminal::resolve_for_session(&options, Some(&session_name("alpha")), context());
    let button_start = String::from_utf8(button_tracking.attach_start_sequence()).expect("utf8");
    assert!(button_start.contains("\u{1b}[?1002h"));
    assert!(!button_start.contains("\u{1b}[?1003h"));
}

/// The prelude's title/path gate, exercised straight against the capability
/// layer. `set-titles off` resolves no title, which on tmux 3.7b means the
/// attached client writes neither OSC 0 nor OSC 7 even when the terminal
/// advertises `title` and `osc7`.
#[test]
fn render_prelude_without_resolved_title_writes_neither_title_nor_path() {
    let mut options = title_capable_options();
    options
        .set(
            ScopeSelector::Window(rmux_proto::WindowTarget::with_window(
                session_name("alpha"),
                0,
            )),
            OptionName::CursorColour,
            "red".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("cursor colour set succeeds");

    let terminal = title_capable_terminal(&options);
    let prelude = render_title_prelude(
        &terminal,
        &options,
        super::ClientTitleUpdate {
            resolved: None,
            path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
            previous: None,
        },
    );

    assert!(
        !prelude.contains("\u{1b}]0;"),
        "set-titles off must not drive the outer title, got {prelude:?}"
    );
    assert!(
        !prelude.contains("\u{1b}]7;"),
        "set-titles off must not drive OSC 7 either, got {prelude:?}"
    );
    // The rest of the prelude is untouched by the title gate.
    assert!(prelude.contains("\u{1b}]12;rgb:cd/00/00\u{7}"));
}

/// A resolved title is the expanded `set-titles-string`, never the bare pane
/// title (issue #182), and it unlocks the neighbouring OSC 7 path.
#[test]
fn render_prelude_writes_resolved_title_and_path() {
    let options = title_capable_options();
    let terminal = title_capable_terminal(&options);

    let prelude = render_title_prelude(
        &terminal,
        &options,
        super::ClientTitleUpdate {
            resolved: Some("RMUXTEST alpha:0"),
            path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
            previous: None,
        },
    );

    assert!(prelude.contains("\u{1b}]0;RMUXTEST alpha:0\u{7}"));
    assert!(prelude.contains("\u{1b}]7;file:///tmp/project\u{7}"));
}

/// tmux compares each expansion against `c->title` / `c->path` and writes only
/// what differs, so a refresh resolving the same values is silent. Measured on
/// tmux 3.7b: a static title and path survive four forced `refresh-client`
/// redraws with exactly one OSC 0 and one OSC 7 on the wire.
#[test]
fn render_prelude_skips_an_unchanged_title_and_path() {
    let options = title_capable_options();
    let terminal = title_capable_terminal(&options);
    let shown = super::ClientTitleState {
        title: Some("RMUXTEST alpha:0".to_owned()),
        path: Some(TITLE_PANE_PATH.to_owned()),
    };

    let prelude = render_title_prelude(
        &terminal,
        &options,
        super::ClientTitleUpdate {
            resolved: Some("RMUXTEST alpha:0"),
            path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
            previous: Some(&shown),
        },
    );
    assert!(
        !prelude.contains("\u{1b}]0;") && !prelude.contains("\u{1b}]7;"),
        "unchanged title and path must not be re-emitted, got {prelude:?}"
    );

    let changed = render_title_prelude(
        &terminal,
        &options,
        super::ClientTitleUpdate {
            resolved: Some("RMUXTEST alpha:1"),
            path: super::ClientPathUpdate::Reported("file:///tmp/other"),
            previous: Some(&shown),
        },
    );
    assert!(changed.contains("\u{1b}]0;RMUXTEST alpha:1\u{7}"));
    assert!(changed.contains("\u{1b}]7;file:///tmp/other\u{7}"));
}

/// tmux 3.7b writes the expanded title verbatim, so a title carrying `ESC ] 0 ;`
/// closes the sequence early and injects into the outer terminal. RMUX keeps
/// its deliberate divergence: control characters are neutralised before the
/// payload reaches the terminal.
#[test]
fn render_prelude_neutralises_control_characters_in_the_title() {
    let options = title_capable_options();
    let terminal = title_capable_terminal(&options);

    let prelude = render_title_prelude(
        &terminal,
        &options,
        super::ClientTitleUpdate {
            resolved: Some("A\u{1b}]0;INJECT\u{7}B\tC"),
            path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
            previous: None,
        },
    );

    let title = prelude
        .split_once("\u{1b}]0;")
        .expect("a title is written")
        .1
        .split_once('\u{7}')
        .expect("the title terminates")
        .0;
    // ESC, BEL and TAB each become a space; the surviving "]0;" is inert text.
    assert_eq!(title, "A ]0;INJECT B C");
    assert!(
        !title.contains('\u{1b}') && !title.contains('\u{7}'),
        "no control character may survive into the title, got {title:?}"
    );
    // Exactly one OSC 0 introducer: the payload cannot open a second one.
    assert_eq!(prelude.matches("\u{1b}]0;").count(), 1);
}

/// A terminal that never advertised TSL/FSL keeps its title untouched, exactly
/// as tmux's `tty_set_title()` returns early without both capabilities. The
/// value is still remembered, matching tmux assigning `c->title` regardless.
#[test]
fn render_prelude_leaves_a_title_incapable_terminal_alone() {
    let options = OptionStore::new();
    let terminal = OuterTerminal::resolve(
        &options,
        // No TERM at all: the Windows Terminal case from issue #182, where no
        // terminal family and no XT flag supply a title capability.
        OuterTerminalContext::default(),
    );
    assert!(
        !terminal.features_string().contains("title"),
        "fixture must not advertise the title capability"
    );

    let update = super::ClientTitleUpdate {
        resolved: Some("RMUXTEST alpha:0"),
        path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
        previous: None,
    };
    let prelude = render_title_prelude(&terminal, &options, update);

    assert!(
        !prelude.contains("\u{1b}]0;") && !prelude.contains("RMUXTEST"),
        "a title-incapable terminal must receive no title, got {prelude:?}"
    );
    let rendered = terminal
        .rendered_client_title(update)
        .expect("set-titles on commits");
    assert_eq!(
        rendered.state().title(),
        Some("RMUXTEST alpha:0"),
        "tmux remembers c->title even when the tty cannot write it"
    );
    // Nothing reached the wire, so the frame stays replaceable in the control
    // queue: a client with no title template must not lose render coalescing
    // just because `set-titles` is on.
    assert!(
        !rendered.wrote(),
        "a terminal with no title template emits no OSC bytes"
    );
}

/// While `set-titles` is off nothing is committed, so the value the terminal
/// still shows survives the option going off and back on (oracle: tmux 3.7b
/// emits exactly one title across an on -> off -> on toggle).
#[test]
fn a_suppressed_title_commits_nothing_and_keeps_the_previous_path() {
    let shown = super::ClientTitleState {
        title: Some("STABLE".to_owned()),
        path: Some(TITLE_PANE_PATH.to_owned()),
    };
    assert!(super::ClientTitleUpdate {
        resolved: None,
        path: super::ClientPathUpdate::Reported("file:///tmp/other"),
        previous: Some(&shown),
    }
    .rendered_by(&title_capable_outer_terminal())
    .is_none());

    // A render that resolves a title but reads no pane path keeps the path the
    // client was already given rather than forgetting it, and writes nothing.
    let rendered = super::ClientTitleUpdate {
        resolved: Some("STABLE"),
        path: super::ClientPathUpdate::Unread,
        previous: Some(&shown),
    }
    .rendered_by(&title_capable_outer_terminal())
    .expect("set-titles on commits");
    assert_eq!(rendered.state(), &shown);
    assert!(
        !rendered.wrote(),
        "a fully deduplicated render puts no OSC bytes in the frame"
    );
}

/// A frame that actually carries OSC 0 / OSC 7 must stay in the control queue:
/// its successor deduplicates against it, so replacing it would strand the
/// outer terminal on the previous title with nothing left to correct it.
#[test]
fn a_title_carrying_render_is_not_a_replaceable_refresh() {
    let shown = super::ClientTitleState {
        title: Some("STABLE".to_owned()),
        path: Some(TITLE_PANE_PATH.to_owned()),
    };
    let wrote = super::ClientTitleUpdate {
        resolved: Some("CHANGED"),
        path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
        previous: Some(&shown),
    }
    .rendered_by(&title_capable_outer_terminal())
    .expect("set-titles on commits");
    assert!(wrote.wrote(), "a changed title puts OSC 0 in the frame");

    let path_only = super::ClientTitleUpdate {
        resolved: Some("STABLE"),
        path: super::ClientPathUpdate::Reported("file:///tmp/other"),
        previous: Some(&shown),
    }
    .rendered_by(&title_capable_outer_terminal())
    .expect("set-titles on commits");
    assert!(path_only.wrote(), "a changed path alone still writes OSC 7");
}

/// A render only commits to the client's remembered identity what it actually
/// put on the wire. The status tick expands under the state lock and commits
/// under the attach lock, so a concurrent refresh can deliver a different title
/// in between; adopting a value this render did not write would then claim the
/// outer terminal shows something it does not, and the next expansion back to
/// that value would be skipped — the stale title of issue #182.
#[test]
fn a_render_that_wrote_nothing_commits_nothing() {
    let shown = super::ClientTitleState {
        title: Some("STABLE".to_owned()),
        path: Some(TITLE_PANE_PATH.to_owned()),
    };

    let deduplicated = super::ClientTitleUpdate {
        resolved: Some("STABLE"),
        path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
        previous: Some(&shown),
    }
    .rendered_by(&title_capable_outer_terminal())
    .expect("set-titles on commits");
    assert!(!deduplicated.wrote());
    assert_eq!(
        deduplicated.committed(),
        None,
        "a fully deduplicated render must not overwrite the remembered title"
    );

    let wrote = super::ClientTitleUpdate {
        resolved: Some("CHANGED"),
        path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
        previous: Some(&shown),
    }
    .rendered_by(&title_capable_outer_terminal())
    .expect("set-titles on commits");
    assert_eq!(
        wrote.committed().and_then(super::ClientTitleState::title),
        Some("CHANGED"),
        "a render that wrote OSC 0 commits what the terminal now shows"
    );

    // A terminal that cannot write the sequence commits nothing either: it was
    // never told, so the next render must still consider the title pending.
    let incapable = super::ClientTitleUpdate {
        resolved: Some("CHANGED"),
        path: super::ClientPathUpdate::Reported(TITLE_PANE_PATH),
        previous: Some(&shown),
    }
    .rendered_by(&title_incapable_outer_terminal())
    .expect("set-titles on commits");
    assert_eq!(incapable.committed(), None);
}

const TITLE_PANE_PATH: &str = "file:///tmp/project";

fn title_capable_options() -> OptionStore {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalFeatures,
            "tmux*:osc7".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-features append succeeds");
    options
}

fn title_capable_terminal(options: &OptionStore) -> OuterTerminal {
    OuterTerminal::resolve(
        options,
        OuterTerminalContext::from_pairs(&[("TERM", "tmux-256color")]),
    )
}

/// A terminal advertising both the title and OSC 7 templates, so what a render
/// records is what it would really put on the wire.
fn title_capable_outer_terminal() -> OuterTerminal {
    title_capable_terminal(&title_capable_options())
}

/// No TERM at all: the Windows Terminal case from issue #182, where no terminal
/// family and no XT flag supply a title capability.
fn title_incapable_outer_terminal() -> OuterTerminal {
    OuterTerminal::resolve(&OptionStore::new(), OuterTerminalContext::default())
}

fn render_title_prelude(
    terminal: &OuterTerminal,
    options: &OptionStore,
    update: super::ClientTitleUpdate<'_>,
) -> String {
    String::from_utf8(terminal.render_prelude(&make_session(), options, CursorScope::Pane, update))
        .expect("utf8")
}

#[test]
fn attach_start_queries_client_theme_reports() {
    let terminal = OuterTerminal::resolve(
        &OptionStore::new(),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    let start = String::from_utf8(terminal.attach_start_sequence()).expect("utf8");
    let stop = String::from_utf8(terminal.attach_stop_sequence()).expect("utf8");

    assert!(start.contains("\u{1b}[?2031h"));
    assert!(start.contains("\u{1b}[?996n"));
    assert!(stop.contains("\u{1b}[?2031l"));
}

#[test]
fn cursor_style_transition_preserves_terminal_default_on_initial_default_attach() {
    let terminal = OuterTerminal::resolve(
        &OptionStore::new(),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    assert_eq!(terminal.render_cursor_style_transition(None, 0), None);
}

#[test]
fn cursor_style_transition_resets_only_when_leaving_an_explicit_style() {
    let terminal = OuterTerminal::resolve(
        &OptionStore::new(),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    assert_eq!(
        terminal.render_cursor_style_transition(Some(6), 0),
        Some("\u{1b}[2 q".to_owned())
    );
    assert_eq!(
        terminal.render_cursor_style_transition(Some(0), 6),
        Some("\u{1b}[6 q".to_owned())
    );
    assert_eq!(terminal.render_cursor_style_transition(Some(6), 6), None);
}

#[test]
fn clipboard_encoding_honours_feature_and_set_clipboard_option() {
    let mut enabled_options = OptionStore::new();
    enabled_options
        .set(
            ScopeSelector::Global,
            OptionName::SetClipboard,
            "external".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("set-clipboard set succeeds");
    let enabled = OuterTerminal::resolve(
        &enabled_options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    let encoded = String::from_utf8(
        enabled
            .encode_forced_clipboard_set(b"hi")
            .expect("clipboard write is available"),
    )
    .expect("utf8");
    assert_eq!(encoded, "\u{1b}]52;;aGk=\u{7}");
    // Under `external` an application's inbound OSC 52 is NOT relayed to the
    // outer terminal: tmux gates that path on set-clipboard == on only
    // (input.c input_osc_52 returns early unless set-clipboard == 2), so an
    // untrusted pane cannot drive the system clipboard under the default.
    assert!(!enabled.clipboard_passthrough_enabled());
    // tmux's own selections (copy-mode yank / `set-buffer -w`) still forward
    // under `external` (window-copy.c gates them on set-clipboard != 0).
    assert!(enabled.encode_clipboard_set(b"hi").is_some());

    let mut on_options = OptionStore::new();
    on_options
        .set(
            ScopeSelector::Global,
            OptionName::SetClipboard,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("set-clipboard set succeeds");
    let on = OuterTerminal::resolve(
        &on_options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    // `on` is the opt-in that relays inbound application OSC 52 to the outer.
    assert!(on.clipboard_passthrough_enabled());

    let mut disabled_options = OptionStore::new();
    disabled_options
        .set(
            ScopeSelector::Global,
            OptionName::SetClipboard,
            "off".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("set-clipboard set succeeds");
    let disabled = OuterTerminal::resolve(
        &disabled_options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    assert!(!disabled.clipboard_passthrough_enabled());
    assert!(disabled.encode_forced_clipboard_set(b"hi").is_some());
}

#[test]
fn sync_wrapper_brackets_render_frames_when_supported() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalFeatures,
            "xterm*:sync".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-features append succeeds");
    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    let wrapped = String::from_utf8(terminal.wrap_render_frame(b"frame")).expect("utf8");
    assert_eq!(wrapped, "\u{1b}[?2026hframe\u{1b}[?2026l");
}

#[test]
fn terminal_override_can_disable_sync_wrapper_after_feature_match() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalFeatures,
            "xterm*:sync".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-features append succeeds");
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalOverrides,
            "xterm*:Sync@".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-overrides append succeeds");
    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    assert_eq!(terminal.wrap_render_frame(b"frame"), b"frame");
    assert!(!terminal
        .features_string()
        .split(',')
        .any(|feature| feature == "sync"));
}

#[test]
fn decode_capability_string_handles_octal_escapes() {
    assert_eq!(
        super::decode_capability_string("\\033[H"),
        "\x1b[H",
        "\\033 should decode to ESC"
    );
    assert_eq!(
        super::decode_capability_string("\\007"),
        "\x07",
        "\\007 should decode to BEL"
    );
    assert_eq!(
        super::decode_capability_string("\\0"),
        "\x00",
        "\\0 alone should decode to NUL"
    );
}

#[test]
fn decode_capability_string_handles_vis_escapes() {
    assert_eq!(
        super::decode_capability_string("\\s"),
        " ",
        "\\s should decode to space"
    );
    assert_eq!(
        super::decode_capability_string("\\v"),
        "\x0b",
        "\\v should decode to vertical tab"
    );
    assert_eq!(
        super::decode_capability_string("\\^C"),
        "\x03",
        "\\^C should decode to ctrl-C"
    );
    assert_eq!(
        super::decode_capability_string("\\^?"),
        "\x7f",
        "\\^? should decode to DEL"
    );
}

#[test]
fn decode_capability_string_preserves_existing_escapes() {
    assert_eq!(super::decode_capability_string("\\E[H"), "\x1b[H");
    assert_eq!(super::decode_capability_string("\\e[H"), "\x1b[H");
    assert_eq!(super::decode_capability_string("\\n"), "\n");
    assert_eq!(super::decode_capability_string("\\\\"), "\\");
    assert_eq!(super::decode_capability_string("\\:"), ":");
    assert_eq!(super::decode_capability_string("\\"), "\\");
}

#[test]
fn decode_capability_string_with_mixed_octal_and_text() {
    assert_eq!(
        super::decode_capability_string("\\033[?2026%p1%dq"),
        "\x1b[?2026%p1%dq"
    );
}

#[test]
fn override_with_octal_encoded_value_resolves_correctly() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalOverrides,
            "dumb*:Ss=\\033[%p1%d q".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-overrides append succeeds");

    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "dumb")]),
    );

    let style = terminal
        .render_cursor_style(2)
        .expect("cursor style should be available");
    assert_eq!(style, "\x1b[2 q");
}

#[test]
fn split_override_segments_handles_escaped_colons_and_empty_segments() {
    let segments = super::split_override_segments("a::b:c");
    assert_eq!(segments, vec!["a:b", "c"]);

    let segments = super::split_override_segments("pattern:");
    assert_eq!(segments, vec!["pattern", ""]);

    let segments = super::split_override_segments("");
    assert_eq!(segments, vec![""]);
}

#[test]
fn empty_term_skips_feature_and_override_matching() {
    let options = OptionStore::new();
    let terminal = OuterTerminal::resolve(&options, OuterTerminalContext::default());
    assert_eq!(terminal.features_string(), "");
}

#[test]
fn sync_wrapper_passes_through_empty_frames() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalFeatures,
            "xterm*:sync".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-features append succeeds");
    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    let wrapped = terminal.wrap_render_frame(b"");
    assert!(wrapped.is_empty());
}

#[test]
fn sanitize_osc_payload_strips_bel_and_esc() {
    let sanitized = super::sanitize_osc_payload("hello\x07world\x1b[0m");
    assert!(!sanitized.contains('\x07'));
    assert!(!sanitized.contains('\x1b'));
    assert_eq!(sanitized, "hello world [0m");
}

#[test]
fn base64_encoding_edge_cases() {
    assert_eq!(super::encode_base64(b""), "");
    assert_eq!(super::encode_base64(b"f"), "Zg==");
    assert_eq!(super::encode_base64(b"fo"), "Zm8=");
    assert_eq!(super::encode_base64(b"foo"), "Zm9v");
    assert_eq!(super::encode_base64(b"foob"), "Zm9vYg==");
    assert_eq!(super::encode_base64(b"fooba"), "Zm9vYmE=");
    assert_eq!(super::encode_base64(b"foobar"), "Zm9vYmFy");
}

#[test]
fn clipboard_encoding_rejects_empty_bytes() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::SetClipboard,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("set-clipboard set succeeds");
    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    assert!(terminal.encode_forced_clipboard_set(b"").is_none());
}

#[test]
fn colour_to_rgb_none_default_terminal_return_none() {
    assert!(super::colour_to_rgb(super::COLOUR_NONE).is_none());
    assert!(super::colour_to_rgb(super::COLOUR_DEFAULT).is_none());
    assert!(super::colour_to_rgb(super::COLOUR_TERMINAL).is_none());
}

#[test]
fn colour_to_rgb_256_palette_boundaries() {
    // Index 0 = basic black
    assert_eq!(
        super::colour_to_rgb(super::COLOUR_FLAG_256),
        Some((0, 0, 0))
    );
    // Index 15 = basic bright white
    assert_eq!(
        super::colour_to_rgb(super::COLOUR_FLAG_256 | 15),
        Some((255, 255, 255))
    );
    // Index 16 = first cube colour (black)
    assert_eq!(
        super::colour_to_rgb(super::COLOUR_FLAG_256 | 16),
        Some((0, 0, 0))
    );
    // Index 231 = last cube colour (white)
    assert_eq!(
        super::colour_to_rgb(super::COLOUR_FLAG_256 | 231),
        Some((255, 255, 255))
    );
    // Index 232 = first greyscale
    assert_eq!(
        super::colour_to_rgb(super::COLOUR_FLAG_256 | 232),
        Some((8, 8, 8))
    );
    // Index 255 = last greyscale
    assert_eq!(
        super::colour_to_rgb(super::COLOUR_FLAG_256 | 255),
        Some((238, 238, 238))
    );
}

#[test]
fn colour_to_rgb_bright_ansi_colours() {
    // SGR 90 = bright black
    assert_eq!(super::colour_to_rgb(90), Some((127, 127, 127)));
    // SGR 97 = bright white
    assert_eq!(super::colour_to_rgb(97), Some((255, 255, 255)));
}

#[test]
fn transition_sequence_emits_disable_then_enable_on_change() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::FocusEvents,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("focus-events set succeeds");

    let with_focus = OuterTerminal::resolve_for_session(
        &options,
        Some(&session_name("alpha")),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    let without_focus = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    // Transition from focus-enabled to focus-disabled should emit disable.
    let seq = String::from_utf8(without_focus.transition_sequence_from(&with_focus)).expect("utf8");
    assert!(seq.contains("\u{1b}[?1004l"));

    // Transition from focus-disabled to focus-enabled should emit enable.
    let seq = String::from_utf8(with_focus.transition_sequence_from(&without_focus)).expect("utf8");
    assert!(seq.contains("\u{1b}[?1004h"));
}

#[test]
fn transition_sequence_toggles_mouse_reporting_with_session_scope() {
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::Mouse,
            "on".to_owned(),
            SetOptionMode::Replace,
        )
        .expect("mouse set succeeds");

    let enabled = OuterTerminal::resolve_for_session(
        &options,
        Some(&session_name("alpha")),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );
    let disabled = OuterTerminal::resolve_for_session(
        &OptionStore::new(),
        Some(&session_name("alpha")),
        OuterTerminalContext::from_pairs(&[("TERM", "xterm-256color")]),
    );

    let seq = String::from_utf8(disabled.transition_sequence_from(&enabled)).expect("utf8");
    assert!(seq.contains("\u{1b}[?1000l"));
    assert!(seq.contains("\u{1b}[?1002l"));
    assert!(seq.contains("\u{1b}[?1006l"));
    assert!(seq.contains(MOUSE_DISABLE_SEQUENCE));

    let seq = String::from_utf8(enabled.transition_sequence_from(&disabled)).expect("utf8");
    assert!(seq.contains("\u{1b}[?1006h"));
    assert!(seq.contains("\u{1b}[?1002h"));
    assert!(seq.contains("\u{1b}[?1000h"));
    assert!(seq.contains(MOUSE_ENABLE_SEQUENCE));
}

#[test]
fn parse_capability_override_edge_cases() {
    // Bare name (no = or @)
    let (name, value, remove) = super::parse_capability_override("Tc").unwrap();
    assert_eq!(name, "Tc");
    assert!(value.is_none());
    assert!(!remove);

    // Remove with @
    let (name, value, remove) = super::parse_capability_override("AX@").unwrap();
    assert_eq!(name, "AX");
    assert!(value.is_none());
    assert!(remove);

    // Value with =
    let (name, value, remove) = super::parse_capability_override("Ss=\\E[q").unwrap();
    assert_eq!(name, "Ss");
    assert_eq!(value, Some("\\E[q"));
    assert!(!remove);

    // Empty string
    assert!(super::parse_capability_override("").is_none());

    // Whitespace trimmed
    let (name, value, remove) = super::parse_capability_override("  Tc  ").unwrap();
    assert_eq!(name, "Tc");
    assert!(value.is_none());
    assert!(!remove);
}

#[test]
fn override_removal_wins_over_xt_reintroduction() {
    // XT triggers bpaste/focus/title, but if an explicit Enbp@ override
    // removes bpaste, the second override pass must honour the removal.
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalOverrides,
            "custom*:XT:Enbp@:Dsbp@".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-overrides append succeeds");

    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "custom-term")]),
    );

    let features = terminal.features_string();
    // XT should enable focus and title.
    assert!(features.contains("focus"), "focus should be active");
    assert!(features.contains("title"), "title should be active");
    // But bpaste was explicitly removed.
    assert!(
        !features.contains("bpaste"),
        "bpaste should be removed by override"
    );
}

#[test]
fn override_removal_wins_over_tc_rgb() {
    // Tc triggers RGB, but if AX@ removes default_colours, RGB should
    // still be set (Tc only controls RGB, not AX). Verify Tc works and
    // AX@ is independent.
    let mut options = OptionStore::new();
    options
        .set(
            ScopeSelector::Global,
            OptionName::TerminalOverrides,
            "plain*:Tc:AX@".to_owned(),
            SetOptionMode::Append,
        )
        .expect("terminal-overrides append succeeds");

    let terminal = OuterTerminal::resolve(
        &options,
        OuterTerminalContext::from_pairs(&[("TERM", "plain-term")]),
    );

    let features = terminal.features_string();
    assert!(features.contains("RGB"), "Tc should enable RGB");
}