markdown-tui-explorer 1.27.0

A terminal-based markdown file browser and viewer with search, syntax highlighting, and live reload
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
//! Per-theme `Tokens` constructors. One `fn` per `Theme` variant.
//!
//! Conventions used here:
//!
//! * Each theme starts with its **base hues** (the colours the theme's
//!   designer chose). Everything else either reuses a base hue or is
//!   derived from one via [`super::contrast::ColorOps`].
//! * Where a theme's source palette already has a name for a slot
//!   (Solarized's `base02`, Gruvbox's `bg2`, Nord's `nord11`), the
//!   comment carries it through. Future contributors looking to tweak
//!   a theme can find the source-palette name in one place.
//! * Slots that re-use a base hue (e.g. `state.focus = accent.primary`,
//!   `accent.link = accent.primary`) are written as the assignment to
//!   make the relationship explicit. Pure passthrough slots (no
//!   derivation, no relationship) just take the literal `Color`.
//! * The `code as art` bias: prefer **named base hues + assignments**
//!   over a wall of RGB literals. Where a theme's design doesn't allow
//!   simple reuse (Default has many `Color::Cyan` / named-ANSI slots),
//!   keep the explicit values — readability beats forced derivation.
//! * **Code-block background** is sourced from `surface.raised` in the
//!   `From<Tokens> for Palette` mapping — themes don't set it
//!   separately. See [`super::tokens::Syntax`] for rationale.

#![allow(clippy::too_many_lines)]

use super::tokens::*;
use ratatui::style::Color;

/// Default theme — neutral dark background, ANSI named accents. The
/// only theme that uses named (non-RGB) colors heavily, so most slots
/// stay explicit.
pub(super) fn default_() -> Tokens {
    let bg = Color::Rgb(20, 20, 30);
    let raised = Color::Rgb(40, 40, 40);
    let cyan = Color::Cyan;
    let yellow = Color::Yellow;
    Tokens {
        surface: Surface {
            base: bg,
            raised,
            border: Color::DarkGray,
        },
        text: Text {
            primary: Color::Rgb(220, 220, 220),
            muted: Color::DarkGray,
            on_accent: Color::Black,
            title: Color::Rgb(220, 220, 220),
        },
        state: State {
            selection_bg: Color::Rgb(0, 160, 80),
            selection_fg: Color::Black,
            focus: cyan,
            search_bg: yellow,
            current_match_bg: Color::Rgb(255, 120, 0),
            match_fg: Color::Black,
        },
        accent: Accent {
            primary: cyan,
            alt: yellow,
            link: Color::Blue,
        },
        syntax: Syntax {
            inline_code: Color::Green,
            code_fg: Color::Rgb(180, 200, 180),
            code_border: Color::DarkGray,
        },
        heading: Heading {
            h1: cyan,
            h2: Color::Blue,
            h3: Color::Magenta,
            other: Color::White,
        },
        status: Status {
            // Default uses a lower-elevation status bar than `raised`,
            // making explicit rather than `surface.raised`. The design
            // intent is a clear three-tier hierarchy: base < status < raised.
            bg: Color::Rgb(30, 30, 30),
            fg: Color::Gray,
            help_bg: bg,
            gutter: Color::DarkGray,
        },
        list: List {
            marker: yellow,
            task_marker: cyan,
            block_quote_fg: Color::Gray,
            block_quote_border: Color::DarkGray,
        },
        table: Table {
            header: cyan,
            border: Color::DarkGray,
        },
        git: Git {
            new: Color::Rgb(80, 200, 120),
            modified: Color::Rgb(220, 180, 60),
        },
    }
}

/// Dracula — official palette: <https://draculatheme.com/contribute>
pub(super) fn dracula() -> Tokens {
    let bg = Color::Rgb(40, 42, 54);
    let fg = Color::Rgb(248, 248, 242);
    let comment = Color::Rgb(98, 114, 164);
    let current_line = Color::Rgb(68, 71, 90);
    let purple = Color::Rgb(189, 147, 249);
    let pink = Color::Rgb(255, 121, 198);
    let green = Color::Rgb(80, 250, 123);
    let yellow = Color::Rgb(241, 250, 140);
    let cyan = Color::Rgb(139, 233, 253);
    Tokens {
        surface: Surface {
            base: bg,
            raised: bg, // Dracula has only one bg tier; code blocks share it.
            border: current_line,
        },
        text: Text {
            primary: fg,
            muted: comment,
            // Dark text on bright purple: 1.23.0 audit fix (was fg, 2.26:1).
            on_accent: bg,
            title: fg,
        },
        state: State {
            selection_bg: current_line,
            selection_fg: fg,
            focus: purple,
            search_bg: yellow,
            current_match_bg: pink,
            match_fg: bg,
        },
        accent: Accent {
            primary: purple,
            alt: yellow,
            link: cyan,
        },
        syntax: Syntax {
            inline_code: green,
            code_fg: fg,
            code_border: comment,
        },
        heading: Heading {
            h1: pink,
            h2: purple,
            h3: green,
            other: fg,
        },
        status: Status {
            bg,
            // 1.23.0 audit fix: was comment (3.03:1), bumped to foreground.
            fg,
            help_bg: bg,
            gutter: comment,
        },
        list: List {
            marker: yellow,
            task_marker: green,
            block_quote_fg: comment,
            block_quote_border: comment,
        },
        table: Table {
            header: pink,
            border: comment,
        },
        git: Git {
            new: green,
            modified: yellow,
        },
    }
}

/// Solarized Dark — Ethan Schoonover: <https://ethanschoonover.com/solarized/>
pub(super) fn solarized_dark() -> Tokens {
    let base03 = Color::Rgb(0, 43, 54);
    let base02 = Color::Rgb(7, 54, 66);
    let base01 = Color::Rgb(88, 110, 117);
    let base0 = Color::Rgb(131, 148, 150);
    let base1 = Color::Rgb(147, 161, 161);
    let base3 = Color::Rgb(253, 246, 227);
    let yellow = Color::Rgb(181, 137, 0);
    let orange = Color::Rgb(203, 75, 22);
    let blue = Color::Rgb(38, 139, 210);
    let cyan = Color::Rgb(42, 161, 152);
    let green = Color::Rgb(133, 153, 0);
    Tokens {
        surface: Surface {
            base: base03,
            raised: base02,
            border: base01,
        },
        text: Text {
            primary: base0,
            muted: base01,
            // 1.23.0 audit fix: base1 on blue was 1.38:1; black ~6:1.
            on_accent: Color::Rgb(0, 0, 0),
            title: base1,
        },
        state: State {
            // 1.23.0 audit fix: was base02 (= surface.raised → invisible).
            selection_bg: base01,
            selection_fg: base3,
            focus: blue,
            search_bg: yellow,
            current_match_bg: orange,
            // 1.23.0 audit fix: base03 on orange was 3.26:1.
            match_fg: Color::Rgb(0, 0, 0),
        },
        accent: Accent {
            primary: blue,
            alt: yellow,
            link: blue,
        },
        syntax: Syntax {
            inline_code: green,
            // 1.23.0 audit fix: base0 on base02 was 4.11:1; bumped to base1.
            code_fg: base1,
            code_border: base01,
        },
        heading: Heading {
            h1: orange,
            h2: blue,
            h3: cyan,
            other: base0,
        },
        status: Status {
            bg: base02,
            // 1.23.0 audit fix: base01 on base02 was 2.42:1; bumped to base1.
            fg: base1,
            help_bg: base02,
            gutter: base01,
        },
        list: List {
            marker: yellow,
            task_marker: cyan,
            block_quote_fg: base01,
            block_quote_border: base01,
        },
        table: Table {
            header: orange,
            border: base01,
        },
        git: Git {
            new: green,
            modified: yellow,
        },
    }
}

/// Solarized Light — Ethan Schoonover: <https://ethanschoonover.com/solarized/>
///
/// Note: Solarized intentionally ships sub-AA contrast for a "soft"
/// reading look (base00 on base3 ≈ 4.13:1). For a markdown reader where
/// users actually parse text, primary text is bumped to base02 so
/// reading and code blocks both reach AA. Accent slots stay canonical.
pub(super) fn solarized_light() -> Tokens {
    let base02 = Color::Rgb(7, 54, 66);
    let base00 = Color::Rgb(101, 123, 131);
    let base1 = Color::Rgb(147, 161, 161);
    let base2 = Color::Rgb(238, 232, 213);
    let base3 = Color::Rgb(253, 246, 227);
    let yellow = Color::Rgb(181, 137, 0);
    let orange = Color::Rgb(203, 75, 22);
    let blue = Color::Rgb(38, 139, 210);
    let cyan = Color::Rgb(42, 161, 152);
    let green = Color::Rgb(133, 153, 0);
    Tokens {
        surface: Surface {
            base: base3,
            raised: base2,
            border: base2,
        },
        text: Text {
            primary: base02, // 1.23.0 audit fix: was base00, sub-AA.
            muted: base00,   // was base1.
            // 1.23.0 audit fix: base3 on blue was 3.41:1; black ~5:1.
            on_accent: Color::Rgb(0, 0, 0),
            title: base02,
        },
        state: State {
            // 1.23.0 audit fix: was base2 (= surface.raised → invisible).
            selection_bg: base1,
            selection_fg: base02,
            focus: blue,
            search_bg: yellow,
            current_match_bg: orange,
            // 1.23.0 audit fix: base3 on yellow/orange both sub-AA.
            match_fg: Color::Rgb(0, 0, 0),
        },
        accent: Accent {
            primary: blue,
            alt: yellow,
            link: blue,
        },
        syntax: Syntax {
            inline_code: green,
            code_fg: base02, // 1.23.0 audit fix: was base00, 3.64:1.
            code_border: base1,
        },
        heading: Heading {
            h1: orange,
            h2: blue,
            h3: cyan,
            other: base02,
        },
        status: Status {
            bg: base2,
            fg: base02, // 1.23.0 audit fix: was base00, 3.64:1.
            help_bg: base2,
            gutter: base1,
        },
        list: List {
            marker: yellow,
            task_marker: cyan,
            block_quote_fg: base00,
            block_quote_border: base1,
        },
        table: Table {
            header: orange,
            border: base1,
        },
        git: Git {
            new: green,
            modified: yellow,
        },
    }
}

/// Nord — Arctic palette: <https://www.nordtheme.com/docs/colors-and-palettes>
///
/// Polar Night gradient (canonical):
///   nord0 = #2e3440  base background
///   nord1 = #3b4252  raised surface tier
///   nord2 = #434c5e  selection / current-line
///   nord3 = #4c566a  borders / muted text
pub(super) fn nord() -> Tokens {
    let nord0 = Color::Rgb(46, 52, 64);
    let nord1 = Color::Rgb(59, 66, 82);
    // nord2 = (67, 76, 94) — currently no slot uses it; the gradient
    // goes nord0 → nord1 → nord3 (skipping nord2 to keep selection
    // perceptually distinct from raised).
    let nord3 = Color::Rgb(76, 86, 106);
    let nord4 = Color::Rgb(216, 222, 233);
    let nord6 = Color::Rgb(236, 239, 244);
    let nord8 = Color::Rgb(136, 192, 208);
    let nord9 = Color::Rgb(129, 161, 193);
    let nord10 = Color::Rgb(94, 129, 172);
    let nord11 = Color::Rgb(191, 97, 106);
    let nord13 = Color::Rgb(235, 203, 139);
    let nord14 = Color::Rgb(163, 190, 140);
    Tokens {
        surface: Surface {
            base: nord0,
            raised: nord1,
            border: nord3,
        },
        text: Text {
            primary: nord4,
            muted: nord3,
            on_accent: nord0,
            title: nord6,
        },
        state: State {
            // nord3 is the most-elevated Polar Night tier — gives
            // selection a clear two-step lift from `raised` (nord1)
            // while staying canonical. Adjacent tiers (nord1→nord2)
            // measured Δ=1.7 — perceptually too close.
            selection_bg: nord3,
            selection_fg: nord6,
            focus: nord8,
            search_bg: nord13,
            current_match_bg: nord11,
            // 1.23.0 audit fix: nord0 on nord11 was 3.05:1.
            match_fg: Color::Rgb(0, 0, 0),
        },
        accent: Accent {
            primary: nord8,
            alt: nord13,
            link: nord9,
        },
        syntax: Syntax {
            inline_code: nord14,
            code_fg: nord4,
            code_border: nord3,
        },
        heading: Heading {
            h1: nord11,
            h2: nord8,
            h3: nord14,
            other: nord4,
        },
        status: Status {
            bg: nord1,
            // 1.23.0 audit fix: was nord3 on nord1 = 1.36:1, basically illegible.
            fg: nord4,
            help_bg: nord1,
            gutter: nord3,
        },
        list: List {
            marker: nord13,
            task_marker: nord14,
            block_quote_fg: nord3,
            block_quote_border: nord3,
        },
        table: Table {
            header: nord10,
            border: nord3,
        },
        git: Git {
            new: nord14,
            modified: nord13,
        },
    }
}

/// Gruvbox Dark — <https://github.com/morhetz/gruvbox>
pub(super) fn gruvbox_dark() -> Tokens {
    let bg = Color::Rgb(40, 40, 40);
    let bg1 = Color::Rgb(50, 48, 47);
    let bg3 = Color::Rgb(80, 73, 69);
    let bg4 = Color::Rgb(102, 92, 84);
    let fg = Color::Rgb(235, 219, 178);
    let gray = Color::Rgb(146, 131, 116);
    let red = Color::Rgb(251, 73, 52);
    let orange = Color::Rgb(214, 93, 14);
    let yellow = Color::Rgb(250, 189, 47);
    let green = Color::Rgb(184, 187, 38);
    let aqua = Color::Rgb(131, 165, 152);
    Tokens {
        surface: Surface {
            base: bg,
            raised: bg1,
            border: bg3,
        },
        text: Text {
            primary: fg,
            muted: gray,
            on_accent: bg,
            title: fg,
        },
        state: State {
            selection_bg: bg3,
            selection_fg: fg,
            focus: orange,
            search_bg: yellow,
            current_match_bg: red,
            // 1.23.0 audit fix: bg on red was 4.29:1, just under AA.
            match_fg: Color::Rgb(0, 0, 0),
        },
        accent: Accent {
            primary: yellow,
            alt: green,
            link: aqua,
        },
        syntax: Syntax {
            inline_code: green,
            code_fg: fg,
            code_border: bg3,
        },
        heading: Heading {
            h1: red,
            h2: yellow,
            h3: green,
            other: fg,
        },
        status: Status {
            bg: bg1,
            // 1.23.0 audit fix: was gray (3.58:1); bumped to fg.
            fg,
            help_bg: bg1,
            gutter: bg4,
        },
        list: List {
            marker: yellow,
            task_marker: green,
            block_quote_fg: gray,
            block_quote_border: gray,
        },
        table: Table {
            header: orange,
            border: bg3,
        },
        git: Git {
            new: green,
            modified: yellow,
        },
    }
}

/// Gruvbox Light — <https://github.com/morhetz/gruvbox>
pub(super) fn gruvbox_light() -> Tokens {
    let bg = Color::Rgb(251, 241, 199);
    let bg1 = Color::Rgb(235, 219, 178);
    let bg2 = Color::Rgb(213, 196, 161);
    let fg = Color::Rgb(60, 56, 54);
    let fg1 = Color::Rgb(80, 73, 69);
    let gray = Color::Rgb(146, 131, 116);
    let red = Color::Rgb(204, 36, 29);
    let orange = Color::Rgb(214, 93, 14);
    let yellow = Color::Rgb(215, 153, 33);
    let green = Color::Rgb(152, 151, 26);
    let aqua = Color::Rgb(104, 157, 106);
    let blue = Color::Rgb(69, 133, 136);
    let purple = Color::Rgb(177, 98, 134);
    Tokens {
        surface: Surface {
            base: bg,
            raised: bg1,
            border: bg2,
        },
        text: Text {
            primary: fg,
            muted: gray,
            on_accent: fg,
            title: fg,
        },
        state: State {
            // 1.23.0 audit fix: was bg1 (= surface.raised → invisible).
            selection_bg: bg2,
            selection_fg: fg,
            focus: orange,
            search_bg: yellow,
            current_match_bg: orange,
            // 1.23.0 audit fix: bg on yellow/orange both sub-AA.
            match_fg: Color::Rgb(0, 0, 0),
        },
        accent: Accent {
            primary: yellow,
            alt: green,
            link: blue,
        },
        syntax: Syntax {
            inline_code: purple,
            code_fg: fg,
            code_border: bg2,
        },
        heading: Heading {
            h1: red,
            h2: yellow,
            h3: green,
            other: fg,
        },
        status: Status {
            bg: bg1,
            fg: fg1,
            help_bg: bg1,
            gutter: gray,
        },
        list: List {
            marker: yellow,
            task_marker: aqua,
            block_quote_fg: gray,
            block_quote_border: bg2,
        },
        table: Table {
            header: orange,
            border: bg2,
        },
        git: Git {
            new: green,
            modified: yellow,
        },
    }
}

/// GitHub Light — Primer Primitives: <https://primer.style/primitives/colors>
pub(super) fn github_light() -> Tokens {
    let canvas = Color::Rgb(255, 255, 255);
    let subtle = Color::Rgb(246, 248, 250);
    let border = Color::Rgb(208, 215, 222);
    let fg = Color::Rgb(31, 35, 40);
    let muted = Color::Rgb(101, 109, 118);
    let blue = Color::Rgb(9, 105, 218); // accent.fg
    let amber = Color::Rgb(154, 103, 0); // attention.fg
    let green = Color::Rgb(26, 127, 55); // success.fg
    let red = Color::Rgb(207, 34, 46); // danger.fg
    let amber_emph = Color::Rgb(255, 211, 61); // attention.emphasis
    let severe_emph = Color::Rgb(255, 143, 0); // severe.emphasis
    let accent_subtle = Color::Rgb(221, 244, 255);
    Tokens {
        surface: Surface {
            base: canvas,
            raised: subtle,
            border,
        },
        text: Text {
            primary: fg,
            muted,
            // White on the vivid blue — `selection_fg` is also #0969da which
            // would produce invisible blue-on-blue text if used on accent.
            on_accent: canvas,
            title: fg,
        },
        state: State {
            selection_bg: accent_subtle,
            selection_fg: blue,
            focus: blue,
            search_bg: amber_emph,
            current_match_bg: severe_emph,
            match_fg: fg,
        },
        accent: Accent {
            primary: blue,
            alt: amber,
            link: blue,
        },
        syntax: Syntax {
            inline_code: red,
            code_fg: fg,
            code_border: border,
        },
        heading: Heading {
            h1: blue,
            h2: amber,
            h3: green,
            other: fg,
        },
        status: Status {
            bg: subtle,
            fg: muted,
            help_bg: subtle,
            gutter: muted,
        },
        list: List {
            marker: amber,
            task_marker: green,
            block_quote_fg: muted,
            block_quote_border: border,
        },
        table: Table {
            header: blue,
            border,
        },
        git: Git {
            new: green,
            modified: amber,
        },
    }
}