vtcode-tui 0.98.3

Reusable TUI primitives and session API for VT Code-style terminal interfaces
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
//! Syntax Highlighting Engine
//!
//! Global syntax highlighting using `syntect` with TextMate themes.
//! Follows the architecture from OpenAI Codex PRs #11447 and #12581.
//!
//! # Architecture
//!
//! - **SyntaxSet**: Process-global singleton (~250 grammars, loaded once)
//! - **ThemeSet**: Process-global singleton loaded once
//! - **Highlighting**: Guardrails skip large inputs (>512KB or >10K lines)
//!
//! # Usage
//!
//! ```rust
//! use vtcode_tui::ui::syntax_highlight::{
//!     get_active_syntax_theme, highlight_code_to_segments,
//! };
//!
//! // Auto-resolve syntax theme from current UI theme
//! let syntax_theme = get_active_syntax_theme();
//!
//! // Highlight code with proper theme
//! let code = "fn main() { println!(\"hi\"); }";
//! let segments = highlight_code_to_segments(code, Some("rust"), syntax_theme);
//! assert!(!segments.is_empty());
//! ```
//!
//! # Performance
//!
//! - Single SyntaxSet load (~1MB, ~50ms)
//! - Single ThemeSet load shared by all highlighters
//! - Input guardrails prevent highlighting huge files
//! - Parser state preserved across multiline constructs

use crate::ui::theme::get_syntax_theme_for_ui_theme;
use anstyle::{Ansi256Color, AnsiColor, Effects, RgbColor, Style as AnstyleStyle};
use once_cell::sync::Lazy;
use syntect::highlighting::{FontStyle, Highlighter, Theme, ThemeSet};
use syntect::parsing::{Scope, SyntaxReference, SyntaxSet};
use syntect::util::LinesWithEndings;
use tracing::warn;
use vtcode_commons::ansi_codes::RESET;

/// Default syntax highlighting theme
const DEFAULT_THEME_NAME: &str = "base16-ocean.dark";

/// Input size guardrail - skip highlighting for files > 512 KB
const MAX_INPUT_SIZE_BYTES: usize = 512 * 1024;

/// Input line guardrail - skip highlighting for files > 10K lines
const MAX_INPUT_LINES: usize = 10_000;

// Syntect/bat encode ANSI palette semantics in alpha:
// `a=0` => ANSI palette index stored in `r`, `a=1` => terminal default.
const ANSI_ALPHA_INDEX: u8 = 0x00;
const ANSI_ALPHA_DEFAULT: u8 = 0x01;
const OPAQUE_ALPHA: u8 = u8::MAX;

/// Global SyntaxSet singleton (~250 grammars)
static SHARED_SYNTAX_SET: Lazy<SyntaxSet> = Lazy::new(SyntaxSet::load_defaults_newlines);

/// Global ThemeSet singleton.
static SHARED_THEME_SET: Lazy<ThemeSet> = Lazy::new(|| match ThemeSet::load_defaults() {
    defaults if !defaults.themes.is_empty() => defaults,
    _ => {
        warn!("Failed to load default syntax highlighting themes");
        ThemeSet {
            themes: Default::default(),
        }
    }
});

/// Get the global SyntaxSet reference
#[inline]
pub fn syntax_set() -> &'static SyntaxSet {
    &SHARED_SYNTAX_SET
}

/// Find syntax by language token (e.g., "rust", "python")
#[inline]
pub fn find_syntax_by_token(token: &str) -> &'static SyntaxReference {
    SHARED_SYNTAX_SET
        .find_syntax_by_token(token)
        .unwrap_or_else(|| SHARED_SYNTAX_SET.find_syntax_plain_text())
}

/// Find syntax by exact name
#[inline]
pub fn find_syntax_by_name(name: &str) -> Option<&'static SyntaxReference> {
    SHARED_SYNTAX_SET.find_syntax_by_name(name)
}

/// Find syntax by file extension
#[inline]
pub fn find_syntax_by_extension(ext: &str) -> Option<&'static SyntaxReference> {
    SHARED_SYNTAX_SET.find_syntax_by_extension(ext)
}

/// Get plain text syntax fallback
#[inline]
pub fn find_syntax_plain_text() -> &'static SyntaxReference {
    SHARED_SYNTAX_SET.find_syntax_plain_text()
}

fn fallback_theme() -> Theme {
    SHARED_THEME_SET
        .themes
        .values()
        .next()
        .cloned()
        .unwrap_or_default()
}

fn plain_text_line_segments(code: &str) -> Vec<Vec<(syntect::highlighting::Style, String)>> {
    let mut result = Vec::new();
    let mut ends_with_newline = false;
    for line in LinesWithEndings::from(code) {
        ends_with_newline = line.ends_with('\n');
        let trimmed = line.trim_end_matches('\n');
        result.push(vec![(
            syntect::highlighting::Style::default(),
            trimmed.to_string(),
        )]);
    }

    if ends_with_newline {
        result.push(Vec::new());
    }

    result
}

/// Load a theme from the process-global theme set.
///
/// # Arguments
/// * `theme_name` - Theme identifier (TextMate theme name)
/// * `cache` - Ignored. Kept for API compatibility.
///
/// # Returns
/// Cloned theme instance (safe for multi-threaded use)
pub fn load_theme(theme_name: &str, _cache: bool) -> Theme {
    if let Some(theme) = SHARED_THEME_SET.themes.get(theme_name) {
        theme.clone()
    } else {
        warn!(
            theme = theme_name,
            "Unknown syntax highlighting theme, falling back to default"
        );
        fallback_theme()
    }
}

/// Get the default syntax theme name
#[inline]
pub fn default_theme_name() -> String {
    DEFAULT_THEME_NAME.to_string()
}

/// Get all available theme names
pub fn available_themes() -> Vec<String> {
    SHARED_THEME_SET.themes.keys().cloned().collect()
}

/// Check if input should be highlighted (guardrails)
#[inline]
pub fn should_highlight(code: &str) -> bool {
    code.len() <= MAX_INPUT_SIZE_BYTES && code.lines().count() <= MAX_INPUT_LINES
}

/// Get the recommended syntax theme for the current UI theme
///
/// This ensures syntax highlighting colors complement the UI theme background.
/// Based on OpenAI Codex PRs #11447 and #12581.
#[inline]
pub fn get_active_syntax_theme() -> &'static str {
    get_syntax_theme_for_ui_theme(&crate::ui::theme::active_theme_id())
}

/// Get the recommended syntax theme for a specific UI theme
#[inline]
pub fn get_syntax_theme(theme: &str) -> &'static str {
    get_syntax_theme_for_ui_theme(theme)
}

/// Raw RGB diff backgrounds extracted from syntax theme scopes.
///
/// Prefers `markup.inserted` / `markup.deleted` and falls back to
/// `diff.inserted` / `diff.deleted`.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct DiffScopeBackgroundRgbs {
    pub inserted: Option<(u8, u8, u8)>,
    pub deleted: Option<(u8, u8, u8)>,
}

/// Resolve diff-scope background colors from the currently active syntax theme.
pub fn diff_scope_background_rgbs() -> DiffScopeBackgroundRgbs {
    let theme_name = get_active_syntax_theme();
    let theme = load_theme(theme_name, true);
    diff_scope_background_rgbs_for_theme(&theme)
}

fn diff_scope_background_rgbs_for_theme(theme: &Theme) -> DiffScopeBackgroundRgbs {
    let highlighter = Highlighter::new(theme);
    let inserted = scope_background_rgb(&highlighter, "markup.inserted")
        .or_else(|| scope_background_rgb(&highlighter, "diff.inserted"));
    let deleted = scope_background_rgb(&highlighter, "markup.deleted")
        .or_else(|| scope_background_rgb(&highlighter, "diff.deleted"));
    DiffScopeBackgroundRgbs { inserted, deleted }
}

fn scope_background_rgb(highlighter: &Highlighter<'_>, scope_name: &str) -> Option<(u8, u8, u8)> {
    let scope = Scope::new(scope_name).ok()?;
    let background = highlighter.style_mod_for_stack(&[scope]).background?;
    Some((background.r, background.g, background.b))
}

fn ansi_palette_color(index: u8) -> anstyle::Color {
    match index {
        0x00 => AnsiColor::Black.into(),
        0x01 => AnsiColor::Red.into(),
        0x02 => AnsiColor::Green.into(),
        0x03 => AnsiColor::Yellow.into(),
        0x04 => AnsiColor::Blue.into(),
        0x05 => AnsiColor::Magenta.into(),
        0x06 => AnsiColor::Cyan.into(),
        0x07 => AnsiColor::White.into(),
        index => Ansi256Color(index).into(),
    }
}

fn convert_syntect_color(color: syntect::highlighting::Color) -> Option<anstyle::Color> {
    match color.a {
        // Bat-compatible encoding for ANSI-family themes.
        ANSI_ALPHA_INDEX => Some(ansi_palette_color(color.r)),
        // Preserve terminal defaults rather than forcing black.
        ANSI_ALPHA_DEFAULT => None,
        // Standard syntect themes use opaque RGB values.
        OPAQUE_ALPHA => Some(RgbColor(color.r, color.g, color.b).into()),
        // Some theme dumps use other alpha values; keep them readable as RGB.
        _ => Some(RgbColor(color.r, color.g, color.b).into()),
    }
}

fn convert_syntect_style(style: syntect::highlighting::Style) -> AnstyleStyle {
    let mut effects = Effects::new();
    if style.font_style.contains(FontStyle::BOLD) {
        effects |= Effects::BOLD;
    }
    if style.font_style.contains(FontStyle::ITALIC) {
        effects |= Effects::ITALIC;
    }
    if style.font_style.contains(FontStyle::UNDERLINE) {
        effects |= Effects::UNDERLINE;
    }

    AnstyleStyle::new()
        .fg_color(convert_syntect_color(style.foreground))
        .bg_color(convert_syntect_color(style.background))
        .effects(effects)
}

#[inline]
fn select_syntax(language: Option<&str>) -> &'static SyntaxReference {
    language
        .map(find_syntax_by_token)
        .unwrap_or_else(find_syntax_plain_text)
}

/// Highlight code and return styled segments per line.
///
/// Uses `LinesWithEndings` semantics by preserving an empty trailing line
/// when the input ends with `\n`.
pub fn highlight_code_to_line_segments(
    code: &str,
    language: Option<&str>,
    theme_name: &str,
) -> Vec<Vec<(syntect::highlighting::Style, String)>> {
    let theme = load_theme(theme_name, true);
    highlight_code_to_line_segments_with_theme(code, language, &theme)
}

fn highlight_code_to_line_segments_with_theme(
    code: &str,
    language: Option<&str>,
    theme: &Theme,
) -> Vec<Vec<(syntect::highlighting::Style, String)>> {
    if !should_highlight(code) {
        return plain_text_line_segments(code);
    }

    let syntax = select_syntax(language);
    let mut highlighter = syntect::easy::HighlightLines::new(syntax, theme);
    let mut result = Vec::new();
    let mut ends_with_newline = false;

    for line in LinesWithEndings::from(code) {
        ends_with_newline = line.ends_with('\n');
        let trimmed = line.trim_end_matches('\n');
        let segments = match highlighter.highlight_line(trimmed, syntax_set()) {
            Ok(ranges) => ranges
                .into_iter()
                .map(|(style, text)| (style, text.to_string()))
                .collect(),
            Err(_) => vec![(syntect::highlighting::Style::default(), trimmed.to_string())],
        };
        result.push(segments);
    }

    if ends_with_newline {
        result.push(Vec::new());
    }

    result
}

fn highlight_code_to_anstyle_line_segments_with_theme(
    code: &str,
    language: Option<&str>,
    theme: &Theme,
    strip_background: bool,
) -> Vec<Vec<(AnstyleStyle, String)>> {
    highlight_code_to_line_segments_with_theme(code, language, theme)
        .into_iter()
        .map(|ranges| {
            ranges
                .into_iter()
                .filter(|(_, text)| !text.is_empty())
                .map(|(style, text)| {
                    let mut anstyle = convert_syntect_style(style);
                    if strip_background {
                        anstyle = anstyle.bg_color(None);
                    }
                    (anstyle, text)
                })
                .collect()
        })
        .collect()
}

/// Highlight code and convert to `anstyle` segments with optional bg stripping.
pub fn highlight_code_to_anstyle_line_segments(
    code: &str,
    language: Option<&str>,
    theme_name: &str,
    strip_background: bool,
) -> Vec<Vec<(AnstyleStyle, String)>> {
    let theme = load_theme(theme_name, true);
    highlight_code_to_anstyle_line_segments_with_theme(code, language, &theme, strip_background)
}

/// Highlight one line and convert to `anstyle` segments with optional bg stripping.
pub fn highlight_line_to_anstyle_segments(
    line: &str,
    language: Option<&str>,
    theme_name: &str,
    strip_background: bool,
) -> Option<Vec<(AnstyleStyle, String)>> {
    highlight_code_to_anstyle_line_segments(line, language, theme_name, strip_background)
        .into_iter()
        .next()
}

/// Highlight code and return styled segments
///
/// # Arguments
/// * `code` - Source code to highlight
/// * `language` - Optional language hint (auto-detected if None)
/// * `theme_name` - Syntax theme name (use `get_active_syntax_theme()` for UI theme sync)
///
/// # Returns
/// Vector of (Style, String) tuples for rendering
///
/// # Performance
/// - Returns None early if input exceeds guardrails
/// - Uses cached theme when available
pub fn highlight_code_to_segments(
    code: &str,
    language: Option<&str>,
    theme_name: &str,
) -> Vec<(syntect::highlighting::Style, String)> {
    highlight_code_to_line_segments(code, language, theme_name)
        .into_iter()
        .flatten()
        .collect()
}

/// Highlight a single line (for diff rendering)
///
/// Preserves parser state for multiline constructs
pub fn highlight_line_for_diff(
    line: &str,
    language: Option<&str>,
    theme_name: &str,
) -> Option<Vec<(syntect::highlighting::Style, String)>> {
    highlight_code_to_line_segments(line, language, theme_name)
        .into_iter()
        .next()
}

/// Convert code to ANSI escape sequences
pub fn highlight_code_to_ansi(code: &str, language: Option<&str>, theme_name: &str) -> String {
    let segments = highlight_code_to_anstyle_line_segments(code, language, theme_name, false);
    let mut output = String::with_capacity(code.len() + segments.len() * 10);

    for (ansi_style, text) in segments.into_iter().flatten() {
        output.push_str(&ansi_style.to_string());
        output.push_str(&text);
        output.push_str(RESET);
    }

    output
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::str::FromStr;
    use syntect::highlighting::Color as SyntectColor;
    use syntect::highlighting::ScopeSelectors;
    use syntect::highlighting::StyleModifier;
    use syntect::highlighting::ThemeItem;
    use syntect::highlighting::ThemeSettings;

    fn theme_item(scope: &str, background: Option<(u8, u8, u8)>) -> ThemeItem {
        ThemeItem {
            scope: ScopeSelectors::from_str(scope).expect("scope selector should parse"),
            style: StyleModifier {
                background: background.map(|(r, g, b)| SyntectColor { r, g, b, a: 255 }),
                ..StyleModifier::default()
            },
        }
    }

    #[test]
    fn test_syntax_set_loaded() {
        let ss = syntax_set();
        assert!(!ss.syntaxes().is_empty());
    }

    #[test]
    fn test_find_syntax_by_token() {
        let rust = find_syntax_by_token("rust");
        assert!(rust.name.contains("Rust"));
    }

    #[test]
    fn test_should_highlight_guardrails() {
        assert!(should_highlight("fn main() {}"));
        assert!(!should_highlight(&"x".repeat(MAX_INPUT_SIZE_BYTES + 1)));
    }

    #[test]
    fn test_get_active_syntax_theme() {
        let theme = get_active_syntax_theme();
        assert!(!theme.is_empty());
    }

    #[test]
    fn test_highlight_code_to_segments() {
        let segments =
            highlight_code_to_segments("fn main() {}", Some("rust"), "base16-ocean.dark");
        assert!(!segments.is_empty());
    }

    #[test]
    fn test_theme_loading_stable() {
        let theme1 = load_theme("base16-ocean.dark", true);
        let theme2 = load_theme("base16-ocean.dark", true);
        assert_eq!(theme1.name, theme2.name);
    }

    #[test]
    fn convert_syntect_style_uses_named_ansi_for_low_palette_indexes() {
        let style = convert_syntect_style(syntect::highlighting::Style {
            foreground: SyntectColor {
                r: 0x02,
                g: 0,
                b: 0,
                a: ANSI_ALPHA_INDEX,
            },
            background: SyntectColor {
                r: 0,
                g: 0,
                b: 0,
                a: OPAQUE_ALPHA,
            },
            font_style: FontStyle::empty(),
        });

        assert_eq!(style.get_fg_color(), Some(AnsiColor::Green.into()));
    }

    #[test]
    fn convert_syntect_style_uses_ansi256_for_high_palette_indexes() {
        let style = convert_syntect_style(syntect::highlighting::Style {
            foreground: SyntectColor {
                r: 0x9a,
                g: 0,
                b: 0,
                a: ANSI_ALPHA_INDEX,
            },
            background: SyntectColor {
                r: 0,
                g: 0,
                b: 0,
                a: OPAQUE_ALPHA,
            },
            font_style: FontStyle::empty(),
        });

        assert_eq!(style.get_fg_color(), Some(Ansi256Color(0x9a).into()));
    }

    #[test]
    fn convert_syntect_style_uses_terminal_default_for_alpha_one() {
        let style = convert_syntect_style(syntect::highlighting::Style {
            foreground: SyntectColor {
                r: 0,
                g: 0,
                b: 0,
                a: ANSI_ALPHA_DEFAULT,
            },
            background: SyntectColor {
                r: 0,
                g: 0,
                b: 0,
                a: OPAQUE_ALPHA,
            },
            font_style: FontStyle::empty(),
        });

        assert_eq!(style.get_fg_color(), None);
    }

    #[test]
    fn convert_syntect_style_falls_back_to_rgb_for_unexpected_alpha() {
        let style = convert_syntect_style(syntect::highlighting::Style {
            foreground: SyntectColor {
                r: 10,
                g: 20,
                b: 30,
                a: 0x80,
            },
            background: SyntectColor {
                r: 0,
                g: 0,
                b: 0,
                a: OPAQUE_ALPHA,
            },
            font_style: FontStyle::empty(),
        });

        assert_eq!(style.get_fg_color(), Some(RgbColor(10, 20, 30).into()));
    }

    #[test]
    fn convert_syntect_style_preserves_effects() {
        let style = convert_syntect_style(syntect::highlighting::Style {
            foreground: SyntectColor {
                r: 10,
                g: 20,
                b: 30,
                a: OPAQUE_ALPHA,
            },
            background: SyntectColor {
                r: 0,
                g: 0,
                b: 0,
                a: OPAQUE_ALPHA,
            },
            font_style: FontStyle::BOLD | FontStyle::ITALIC | FontStyle::UNDERLINE,
        });

        let effects = style.get_effects();
        assert!(effects.contains(Effects::BOLD));
        assert!(effects.contains(Effects::ITALIC));
        assert!(effects.contains(Effects::UNDERLINE));
    }

    #[test]
    fn highlight_pipeline_decodes_alpha_encoded_theme_colors() {
        let theme = Theme {
            settings: ThemeSettings {
                foreground: Some(SyntectColor {
                    r: 0x02,
                    g: 0,
                    b: 0,
                    a: ANSI_ALPHA_INDEX,
                }),
                background: Some(SyntectColor {
                    r: 0,
                    g: 0,
                    b: 0,
                    a: ANSI_ALPHA_DEFAULT,
                }),
                ..ThemeSettings::default()
            },
            ..Theme::default()
        };

        let segments =
            highlight_code_to_anstyle_line_segments_with_theme("plain text", None, &theme, false);
        assert_eq!(segments.len(), 1);
        assert_eq!(segments[0].len(), 1);
        assert_eq!(
            segments[0][0].0.get_fg_color(),
            Some(AnsiColor::Green.into())
        );
        assert_eq!(segments[0][0].0.get_bg_color(), None);
        assert_eq!(segments[0][0].1, "plain text");
    }

    #[test]
    fn diff_scope_backgrounds_prefer_markup_scope_then_diff_fallback() {
        let theme = Theme {
            settings: ThemeSettings::default(),
            scopes: vec![
                theme_item("markup.inserted", Some((10, 20, 30))),
                theme_item("diff.deleted", Some((40, 50, 60))),
            ],
            ..Theme::default()
        };

        let rgbs = diff_scope_background_rgbs_for_theme(&theme);
        assert_eq!(
            rgbs,
            DiffScopeBackgroundRgbs {
                inserted: Some((10, 20, 30)),
                deleted: Some((40, 50, 60)),
            }
        );
    }

    #[test]
    fn diff_scope_backgrounds_return_none_when_scopes_do_not_match() {
        let theme = Theme {
            settings: ThemeSettings::default(),
            scopes: vec![theme_item("constant.numeric", Some((1, 2, 3)))],
            ..Theme::default()
        };

        let rgbs = diff_scope_background_rgbs_for_theme(&theme);
        assert_eq!(
            rgbs,
            DiffScopeBackgroundRgbs {
                inserted: None,
                deleted: None,
            }
        );
    }

    #[test]
    fn diff_scope_backgrounds_fall_back_to_diff_scopes() {
        let theme = Theme {
            settings: ThemeSettings::default(),
            scopes: vec![
                theme_item("diff.inserted", Some((16, 32, 48))),
                theme_item("diff.deleted", Some((64, 80, 96))),
            ],
            ..Theme::default()
        };

        let rgbs = diff_scope_background_rgbs_for_theme(&theme);
        assert_eq!(
            rgbs,
            DiffScopeBackgroundRgbs {
                inserted: Some((16, 32, 48)),
                deleted: Some((64, 80, 96)),
            }
        );
    }
}