rediff 0.50.0-rc.1

Diff and compare Facet values with detailed structural difference reporting
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
//! Color themes for diff rendering.

use owo_colors::Rgb;
use palette::{FromColor, Lch, LinSrgb, Mix, Srgb};

/// Color theme for diff rendering.
///
/// Defines colors for different kinds of changes. The default uses
/// colorblind-friendly yellow/blue with type-specific value colors.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiffTheme {
    /// Foreground color for deleted content (accent color)
    pub deleted: Rgb,

    /// Foreground color for inserted content (accent color)
    pub inserted: Rgb,

    /// Foreground color for moved content (accent color)
    pub moved: Rgb,

    /// Foreground color for unchanged content
    pub unchanged: Rgb,

    /// Foreground color for keys/field names
    pub key: Rgb,

    /// Foreground color for structural elements like braces, brackets
    pub structure: Rgb,

    /// Foreground color for comments and type hints
    pub comment: Rgb,

    // === Value type base colors ===
    /// Base color for string values
    pub string: Rgb,

    /// Base color for numeric values (integers, floats)
    pub number: Rgb,

    /// Base color for boolean values
    pub boolean: Rgb,

    /// Base color for null/None values
    pub null: Rgb,

    /// Subtle background for deleted lines (None = no background)
    pub deleted_line_bg: Option<Rgb>,

    /// Stronger background highlight for changed values on deleted lines
    pub deleted_highlight_bg: Option<Rgb>,

    /// Subtle background for inserted lines (None = no background)
    pub inserted_line_bg: Option<Rgb>,

    /// Stronger background highlight for changed values on inserted lines
    pub inserted_highlight_bg: Option<Rgb>,

    /// Subtle background for moved lines (None = no background)
    pub moved_line_bg: Option<Rgb>,

    /// Stronger background highlight for changed values on moved lines
    pub moved_highlight_bg: Option<Rgb>,
}

impl Default for DiffTheme {
    fn default() -> Self {
        Self::colorblind_dark()
    }
}

/// Build an sRGB color from LCH (perceptually uniform): same `l`
/// (lightness) and `c` (chroma) with a different `h` (hue) produces
/// colors that *look equally intense* — only the hue differs. This is
/// how deleted/inserted/moved stay visually balanced.
///
/// Lightness is the dominant intensity cue and is preserved exactly;
/// if `(l, c, h)` falls outside the sRGB gamut we *reduce chroma*
/// toward gray until it fits (gamut mapping) rather than clamping each
/// channel — per-channel clamping is what shifts the lightness and
/// makes one hue look muddier than another.
fn lch_rgb(l: f32, c: f32, h: f32) -> Rgb {
    let in_gamut = |s: &Srgb| {
        let e = 1.0 / 512.0; // tolerance for rounding
        (-e..=1.0 + e).contains(&s.red)
            && (-e..=1.0 + e).contains(&s.green)
            && (-e..=1.0 + e).contains(&s.blue)
    };

    let mut chroma = c;
    let srgb: Srgb = loop {
        let s: Srgb = Srgb::from_color(Lch::new(l, chroma, h));
        if chroma <= 0.0 || in_gamut(&s) {
            break s;
        }
        chroma -= 0.5;
    };

    Rgb(
        (srgb.red.clamp(0.0, 1.0) * 255.0).round() as u8,
        (srgb.green.clamp(0.0, 1.0) * 255.0).round() as u8,
        (srgb.blue.clamp(0.0, 1.0) * 255.0).round() as u8,
    )
}

// Hues (LCH degrees) for the three change kinds. Warm amber for
// deletions, cool azure for insertions, magenta for moves — far apart
// on the wheel and distinguishable for most color-vision deficiencies.
const HUE_DELETED: f32 = 75.0;
const HUE_INSERTED: f32 = 255.0;
const HUE_MOVED: f32 = 320.0;

impl DiffTheme {
    /// The default dark-terminal theme.
    ///
    /// Deleted / inserted / moved share the *same lightness and chroma*
    /// at every role (accent fg, line bg, highlight bg) and differ only
    /// in hue, so the two sides of a diff are perceptually balanced —
    /// no more "one side brown, the other gray".
    pub fn colorblind_dark() -> Self {
        // (lightness, chroma) for each role on a dark background.
        const ACCENT: (f32, f32) = (74.0, 52.0);
        const LINE_BG: (f32, f32) = (20.0, 10.0);
        const HL_BG: (f32, f32) = (28.0, 22.0);

        Self {
            deleted: lch_rgb(ACCENT.0, ACCENT.1, HUE_DELETED),
            inserted: lch_rgb(ACCENT.0, ACCENT.1, HUE_INSERTED),
            moved: lch_rgb(ACCENT.0, ACCENT.1, HUE_MOVED),
            unchanged: Rgb(140, 140, 140),
            key: Rgb(140, 140, 140),
            structure: Rgb(220, 220, 220),
            comment: Rgb(100, 100, 100),
            string: Rgb(152, 195, 121),
            number: Rgb(209, 154, 102),
            boolean: Rgb(209, 154, 102),
            null: Rgb(86, 182, 194),
            deleted_line_bg: Some(lch_rgb(LINE_BG.0, LINE_BG.1, HUE_DELETED)),
            inserted_line_bg: Some(lch_rgb(LINE_BG.0, LINE_BG.1, HUE_INSERTED)),
            moved_line_bg: Some(lch_rgb(LINE_BG.0, LINE_BG.1, HUE_MOVED)),
            deleted_highlight_bg: Some(lch_rgb(HL_BG.0, HL_BG.1, HUE_DELETED)),
            inserted_highlight_bg: Some(lch_rgb(HL_BG.0, HL_BG.1, HUE_INSERTED)),
            moved_highlight_bg: Some(lch_rgb(HL_BG.0, HL_BG.1, HUE_MOVED)),
        }
    }

    /// The default light-terminal theme.
    ///
    /// The same symmetric LCH derivation as [`Self::colorblind_dark`],
    /// with the lightnesses flipped: pale tinted backgrounds and darker,
    /// vivid accents that read on a white background. Deleted / inserted
    /// / moved stay perceptually balanced (equal L*/C* per role).
    pub fn colorblind_light() -> Self {
        // Dark, vivid accents on very light tinted backgrounds. The
        // accent is deliberately deep (L* ~34) so highlighted values
        // keep a strong contrast ratio against the pale highlight bg.
        const ACCENT: (f32, f32) = (31.0, 62.0);
        const LINE_BG: (f32, f32) = (93.0, 9.0);
        const HL_BG: (f32, f32) = (85.0, 20.0);

        Self {
            deleted: lch_rgb(ACCENT.0, ACCENT.1, HUE_DELETED),
            inserted: lch_rgb(ACCENT.0, ACCENT.1, HUE_INSERTED),
            moved: lch_rgb(ACCENT.0, ACCENT.1, HUE_MOVED),
            unchanged: Rgb(120, 120, 120),
            key: Rgb(120, 120, 120),
            structure: Rgb(50, 50, 50),
            comment: Rgb(150, 150, 150),
            // Value-type colors darkened for contrast on a light bg.
            string: lch_rgb(45.0, 55.0, 135.0), // green
            number: lch_rgb(50.0, 62.0, 55.0),  // orange
            boolean: lch_rgb(50.0, 62.0, 55.0), // orange
            null: lch_rgb(48.0, 38.0, 210.0),   // cyan
            deleted_line_bg: Some(lch_rgb(LINE_BG.0, LINE_BG.1, HUE_DELETED)),
            inserted_line_bg: Some(lch_rgb(LINE_BG.0, LINE_BG.1, HUE_INSERTED)),
            moved_line_bg: Some(lch_rgb(LINE_BG.0, LINE_BG.1, HUE_MOVED)),
            deleted_highlight_bg: Some(lch_rgb(HL_BG.0, HL_BG.1, HUE_DELETED)),
            inserted_highlight_bg: Some(lch_rgb(HL_BG.0, HL_BG.1, HUE_INSERTED)),
            moved_highlight_bg: Some(lch_rgb(HL_BG.0, HL_BG.1, HUE_MOVED)),
        }
    }

    /// Pick a theme to match the terminal's background.
    ///
    /// Queries the terminal via OSC 11 (using `terminal-colorsaurus`,
    /// which handles non-TTYs, tmux/SSH passthrough, timeouts and
    /// Windows). The query runs **at most once per process** — the
    /// result is cached — and on anything other than a clear "light"
    /// answer (piped output, CI, unsupported terminal, timeout) it
    /// falls back to the dark theme. `REDIFF_THEME=dark|light` forces a
    /// choice and skips the query entirely.
    pub fn auto() -> Self {
        use std::sync::OnceLock;
        static CACHED: OnceLock<DiffTheme> = OnceLock::new();

        CACHED
            .get_or_init(|| {
                if let Ok(forced) = std::env::var("REDIFF_THEME") {
                    return match forced.trim().to_ascii_lowercase().as_str() {
                        "light" => Self::colorblind_light(),
                        _ => Self::colorblind_dark(),
                    };
                }

                use terminal_colorsaurus::{QueryOptions, ThemeMode, theme_mode};
                let mut opts = QueryOptions::default();
                // Keep it snappy: this can run from inside `assert_same!`.
                opts.timeout = std::time::Duration::from_millis(100);

                match theme_mode(opts) {
                    Ok(ThemeMode::Light) => Self::colorblind_light(),
                    _ => Self::colorblind_dark(),
                }
            })
            .clone()
    }

    /// Colorblind-friendly theme - orange vs blue. No backgrounds.
    pub const COLORBLIND_ORANGE_BLUE: Self = Self {
        deleted: Rgb(255, 167, 89),    // #ffa759 warm orange
        inserted: Rgb(97, 175, 239),   // #61afef sky blue
        moved: Rgb(198, 120, 221),     // #c678dd purple/magenta
        unchanged: Rgb(140, 140, 140), // #8c8c8c medium gray (muted)
        key: Rgb(140, 140, 140),       // #8c8c8c medium gray
        structure: Rgb(220, 220, 220), // #dcdcdc light gray (structural elements)
        comment: Rgb(100, 100, 100),   // #646464 dark gray (very muted)
        string: Rgb(152, 195, 121),    // #98c379 green (like One Dark Pro)
        number: Rgb(209, 154, 102),    // #d19a66 orange
        boolean: Rgb(209, 154, 102),   // #d19a66 orange
        null: Rgb(86, 182, 194),       // #56b6c2 cyan
        deleted_line_bg: None,
        deleted_highlight_bg: None,
        inserted_line_bg: None,
        inserted_highlight_bg: None,
        moved_line_bg: None,
        moved_highlight_bg: None,
    };

    /// Colorblind-friendly with line + highlight backgrounds (yellow/blue).
    pub const COLORBLIND_WITH_BG: Self = Self {
        deleted: Rgb(229, 192, 123),   // #e5c07b warm yellow/gold
        inserted: Rgb(97, 175, 239),   // #61afef sky blue
        moved: Rgb(198, 120, 221),     // #c678dd purple/magenta
        unchanged: Rgb(140, 140, 140), // #8c8c8c medium gray (muted)
        key: Rgb(140, 140, 140),       // #8c8c8c medium gray
        structure: Rgb(220, 220, 220), // #dcdcdc light gray (structural elements)
        comment: Rgb(100, 100, 100),   // #646464 dark gray (very muted)
        string: Rgb(152, 195, 121),    // #98c379 green (like One Dark Pro)
        number: Rgb(209, 154, 102),    // #d19a66 orange
        boolean: Rgb(209, 154, 102),   // #d19a66 orange
        null: Rgb(86, 182, 194),       // #56b6c2 cyan
        // Subtle line backgrounds
        deleted_line_bg: Some(Rgb(55, 48, 35)), // medium-dark warm yellow
        inserted_line_bg: Some(Rgb(35, 48, 60)), // medium-dark cool blue
        moved_line_bg: Some(Rgb(50, 40, 60)),   // medium-dark purple
        // Stronger highlight backgrounds for changed values
        deleted_highlight_bg: Some(Rgb(90, 75, 50)), // medium yellow/brown
        inserted_highlight_bg: Some(Rgb(45, 70, 95)), // medium blue
        moved_highlight_bg: Some(Rgb(80, 55, 95)),   // medium purple
    };

    /// Pastel color theme - soft but distinguishable (not colorblind-friendly).
    pub const PASTEL: Self = Self {
        deleted: Rgb(255, 138, 128),   // #ff8a80 saturated coral/salmon
        inserted: Rgb(128, 203, 156),  // #80cb9c saturated mint green
        moved: Rgb(128, 179, 255),     // #80b3ff saturated sky blue
        unchanged: Rgb(140, 140, 140), // #8c8c8c medium gray (muted)
        key: Rgb(140, 140, 140),       // #8c8c8c medium gray
        structure: Rgb(220, 220, 220), // #dcdcdc light gray (structural elements)
        comment: Rgb(100, 100, 100),   // #646464 dark gray (very muted)
        string: Rgb(152, 195, 121),    // #98c379 green
        number: Rgb(209, 154, 102),    // #d19a66 orange
        boolean: Rgb(209, 154, 102),   // #d19a66 orange
        null: Rgb(86, 182, 194),       // #56b6c2 cyan
        deleted_line_bg: None,
        deleted_highlight_bg: None,
        inserted_line_bg: None,
        inserted_highlight_bg: None,
        moved_line_bg: None,
        moved_highlight_bg: None,
    };

    /// One Dark Pro color theme.
    pub const ONE_DARK_PRO: Self = Self {
        deleted: Rgb(224, 108, 117),   // #e06c75 red
        inserted: Rgb(152, 195, 121),  // #98c379 green
        moved: Rgb(97, 175, 239),      // #61afef blue
        unchanged: Rgb(171, 178, 191), // #abb2bf white (normal text)
        key: Rgb(171, 178, 191),       // #abb2bf white
        structure: Rgb(171, 178, 191), // #abb2bf white
        comment: Rgb(92, 99, 112),     // #5c6370 gray (muted)
        string: Rgb(152, 195, 121),    // #98c379 green
        number: Rgb(209, 154, 102),    // #d19a66 orange
        boolean: Rgb(209, 154, 102),   // #d19a66 orange
        null: Rgb(86, 182, 194),       // #56b6c2 cyan
        deleted_line_bg: None,
        deleted_highlight_bg: None,
        inserted_line_bg: None,
        inserted_highlight_bg: None,
        moved_line_bg: None,
        moved_highlight_bg: None,
    };

    /// Tokyo Night color theme.
    pub const TOKYO_NIGHT: Self = Self {
        deleted: Rgb(247, 118, 142),   // red
        inserted: Rgb(158, 206, 106),  // green
        moved: Rgb(122, 162, 247),     // blue
        unchanged: Rgb(192, 202, 245), // white (normal text)
        key: Rgb(192, 202, 245),       // white
        structure: Rgb(192, 202, 245), // white
        comment: Rgb(86, 95, 137),     // gray (muted)
        string: Rgb(158, 206, 106),    // green
        number: Rgb(255, 158, 100),    // orange
        boolean: Rgb(255, 158, 100),   // orange
        null: Rgb(125, 207, 255),      // cyan
        deleted_line_bg: None,
        deleted_highlight_bg: None,
        inserted_line_bg: None,
        inserted_highlight_bg: None,
        moved_line_bg: None,
        moved_highlight_bg: None,
    };

    /// Get the color for a change kind.
    pub const fn color_for(&self, kind: crate::ChangeKind) -> Rgb {
        match kind {
            crate::ChangeKind::Unchanged => self.unchanged,
            crate::ChangeKind::Deleted => self.deleted,
            crate::ChangeKind::Inserted => self.inserted,
            crate::ChangeKind::MovedFrom | crate::ChangeKind::MovedTo => self.moved,
            crate::ChangeKind::Modified => self.deleted, // old value gets deleted color
        }
    }

    /// Blend two colors in linear sRGB space.
    /// `t` ranges from 0.0 (all `a`) to 1.0 (all `b`).
    pub fn blend(a: Rgb, b: Rgb, t: f32) -> Rgb {
        // Convert to linear sRGB for perceptually correct blending
        let a_lin: LinSrgb =
            Srgb::new(a.0 as f32 / 255.0, a.1 as f32 / 255.0, a.2 as f32 / 255.0).into_linear();
        let b_lin: LinSrgb =
            Srgb::new(b.0 as f32 / 255.0, b.1 as f32 / 255.0, b.2 as f32 / 255.0).into_linear();

        // Mix in linear space
        let mixed = a_lin.mix(b_lin, t);

        // Convert back to sRGB
        let result: Srgb = mixed.into();
        Rgb(
            (result.red * 255.0).round() as u8,
            (result.green * 255.0).round() as u8,
            (result.blue * 255.0).round() as u8,
        )
    }

    /// Brighten and saturate a color for use in highlights.
    /// Increases both lightness and saturation in LCH space.
    pub fn brighten_saturate(rgb: Rgb, lightness_boost: f32, chroma_boost: f32) -> Rgb {
        let srgb = Srgb::new(
            rgb.0 as f32 / 255.0,
            rgb.1 as f32 / 255.0,
            rgb.2 as f32 / 255.0,
        );
        let mut lch = Lch::from_color(srgb);

        // Increase lightness
        lch.l = (lch.l + lightness_boost * 100.0).min(100.0);

        // Increase chroma (saturation-like)
        lch.chroma = (lch.chroma + chroma_boost).min(150.0);

        let result: Srgb = Srgb::from_color(lch);
        Rgb(
            (result.red * 255.0).round() as u8,
            (result.green * 255.0).round() as u8,
            (result.blue * 255.0).round() as u8,
        )
    }

    /// Desaturate a color for use in backgrounds.
    /// Reduces saturation (chroma) in LCH space.
    pub fn desaturate(rgb: Rgb, amount: f32) -> Rgb {
        let srgb = Srgb::new(
            rgb.0 as f32 / 255.0,
            rgb.1 as f32 / 255.0,
            rgb.2 as f32 / 255.0,
        );
        let mut lch = Lch::from_color(srgb);

        // Reduce chroma (saturation)
        lch.chroma *= 1.0 - amount;

        let result: Srgb = Srgb::from_color(lch);
        Rgb(
            (result.red * 255.0).round() as u8,
            (result.green * 255.0).round() as u8,
            (result.blue * 255.0).round() as u8,
        )
    }

    /// Get the key color blended for a deleted context.
    pub fn deleted_key(&self) -> Rgb {
        Self::blend(self.key, self.deleted, 0.5)
    }

    /// Get the key color blended for an inserted context.
    pub fn inserted_key(&self) -> Rgb {
        Self::blend(self.key, self.inserted, 0.5)
    }

    /// Get the structure color blended for a deleted context.
    pub fn deleted_structure(&self) -> Rgb {
        Self::blend(self.structure, self.deleted, 0.4)
    }

    /// Get the structure color blended for an inserted context.
    pub fn inserted_structure(&self) -> Rgb {
        Self::blend(self.structure, self.inserted, 0.4)
    }

    /// Get the comment color blended for a deleted context.
    pub fn deleted_comment(&self) -> Rgb {
        Self::blend(self.comment, self.deleted, 0.35)
    }

    /// Get the comment color blended for an inserted context.
    pub fn inserted_comment(&self) -> Rgb {
        Self::blend(self.comment, self.inserted, 0.35)
    }

    // === Value type blending methods ===

    /// Get the string color blended for a deleted context.
    pub fn deleted_string(&self) -> Rgb {
        Self::blend(self.string, self.deleted, 0.7)
    }

    /// Get the string color blended for an inserted context.
    pub fn inserted_string(&self) -> Rgb {
        Self::blend(self.string, self.inserted, 0.7)
    }

    /// Get the number color blended for a deleted context.
    pub fn deleted_number(&self) -> Rgb {
        Self::blend(self.number, self.deleted, 0.7)
    }

    /// Get the number color blended for an inserted context.
    pub fn inserted_number(&self) -> Rgb {
        Self::blend(self.number, self.inserted, 0.7)
    }

    /// Get the boolean color blended for a deleted context.
    pub fn deleted_boolean(&self) -> Rgb {
        Self::blend(self.boolean, self.deleted, 0.7)
    }

    /// Get the boolean color blended for an inserted context.
    pub fn inserted_boolean(&self) -> Rgb {
        Self::blend(self.boolean, self.inserted, 0.7)
    }

    /// Get the null color blended for a deleted context.
    pub fn deleted_null(&self) -> Rgb {
        Self::blend(self.null, self.deleted, 0.7)
    }

    /// Get the null color blended for an inserted context.
    pub fn inserted_null(&self) -> Rgb {
        Self::blend(self.null, self.inserted, 0.7)
    }

    // === Bright highlight colors for values with highlight backgrounds ===

    /// Get the string color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_string(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the string color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_string(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    /// Get the number color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_number(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the number color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_number(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    /// Get the boolean color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_boolean(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the boolean color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_boolean(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    /// Get the null color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_null(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the null color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_null(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    // === Syntax highlight colors (keys, structure, comments with brightened accents) ===

    /// Get the key color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_key(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the key color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_key(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    /// Get the structure color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_structure(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the structure color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_structure(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    /// Get the comment color for a deleted highlight (brightened and saturated accent color).
    pub fn deleted_highlight_comment(&self) -> Rgb {
        Self::brighten_saturate(self.deleted, 0.15, 0.2)
    }

    /// Get the comment color for an inserted highlight (brightened and saturated accent color).
    pub fn inserted_highlight_comment(&self) -> Rgb {
        Self::brighten_saturate(self.inserted, 0.15, 0.2)
    }

    // === Desaturated background getters ===

    // Background getters. Backgrounds are now derived symmetrically in
    // LCH at construction time (`colorblind_dark`), so these return the
    // stored value as-is — the old per-call desaturate/brighten passes
    // are what made deleted go brown while inserted went gray. Kept as
    // methods so call sites (and other themes) are unaffected.

    /// Deleted line background.
    pub fn desaturated_deleted_line_bg(&self) -> Option<Rgb> {
        self.deleted_line_bg
    }

    /// Inserted line background.
    pub fn desaturated_inserted_line_bg(&self) -> Option<Rgb> {
        self.inserted_line_bg
    }

    /// Moved line background.
    pub fn desaturated_moved_line_bg(&self) -> Option<Rgb> {
        self.moved_line_bg
    }

    /// Deleted highlight background.
    pub fn desaturated_deleted_highlight_bg(&self) -> Option<Rgb> {
        self.deleted_highlight_bg
    }

    /// Inserted highlight background.
    pub fn desaturated_inserted_highlight_bg(&self) -> Option<Rgb> {
        self.inserted_highlight_bg
    }

    /// Moved highlight background.
    pub fn desaturated_moved_highlight_bg(&self) -> Option<Rgb> {
        self.moved_highlight_bg
    }
}