edamame 0.1.2

A fast TUI Markdown editor and viewer
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
//! Static row table for the settings overlay.
//!
//! Each row carries a label, an optional description, and a [`RowKind`]
//! whose function-pointer fields tell the overlay how to read, write, and
//! cycle the underlying config field.  Pulling the table out of
//! `settings_overlay.rs` keeps the parent file focused on widget
//! plumbing — adding a new setting only touches this file.

use crate::config::sections::{DEFAULT_HANDLER, MAX_WIDTH_COLS_MIN, VIM_HANDLER};
use crate::config::{Config, DiagramsEnabled, ImagesEnabled, RemoteImagePolicy};
use crate::ui::controls;

/// Row labels for the settings overlay, exported as constants so the
/// App-level live-update wiring in `app/modal/settings.rs` and the
/// row table here can't drift out of sync on a copy change.  Only
/// labels that are referenced from outside this module need a
/// constant; the rest stay as inline string literals.
///
/// Explanatory header rendered as a styled note above the rows.
/// Non-focusable; identified in `build_row_lines` by string equality
/// against this constant so it can be rendered without the usual
/// label/value formatting.
pub(crate) const HEADER_NOTE: &str = "Common options shown below — all others in config.toml";

pub(crate) const LABEL_BIG_H1: &str = "Big H1 headings";
pub(crate) const LABEL_SYNTAX_HIGHLIGHTING: &str = "Syntax highlighting";
pub(crate) const LABEL_VISUAL_LINE_NAV: &str = "Use visual line navigation";
pub(crate) const LABEL_LINE_NUMBERS: &str = "Show line numbers";
pub(crate) const LABEL_SCROLL_SPEED: &str = "Scroll speed";
pub(crate) const LABEL_VIM_MODE: &str = "Vim mode";
pub(crate) const LABEL_BLINK_CURSOR: &str = "Blink cursor";
pub(crate) const LABEL_SHOW_IMAGES: &str = "Show images";
pub(crate) const LABEL_SHOW_DIAGRAMS: &str = "Show diagrams";
pub(crate) const LABEL_SHOW_REMOTE_IMAGES: &str = "  Show remote images";
pub(crate) const LABEL_AUTOSAVE: &str = "Autosave";
pub(crate) const LABEL_LIMIT_WIDTH: &str = "Limit editor width";
pub(crate) const LABEL_DIFF_ON_CHANGE: &str = "Diff when file changes";
pub(crate) const LABEL_TABLE_BUTTONS: &str = "Show table buttons";
pub(crate) const LABEL_CHECK_UPDATES: &str = "Check for updates";

/// Minimum accepted value for [`LABEL_SCROLL_SPEED`].  The
/// dispatcher additionally clamps zero to one as a safety net, but
/// rejecting at the input boundary keeps the persisted value and
/// the live wheel_step in agreement.
const MOUSE_SCROLL_LINES_MIN: usize = 1;

#[derive(Clone, Copy, Debug)]
pub(super) enum RowAction {
    /// "Open config.toml in editor" sentinel.
    OpenExternalEditor,
    /// "Open Config folder" sentinel — fires the `OpenConfigFolder`
    /// action via the OS file manager (`xdg-open` on Linux,
    /// `open` on macOS, `explorer` on Windows).
    OpenConfigFolder,
    /// Enter cycles the value (boolean toggle / enum advance).
    Cycle,
    /// Enter opens an inline text editor (numeric field).
    Edit,
}

/// `(config) -> ControlValue`: read an option row's current value as a
/// normalized [`controls::ControlValue`] for the shared transition layer.
/// Aliased so the `Option<…>` fields below stay under clippy's
/// type-complexity threshold.
pub(super) type ReadValueFn = fn(&Config) -> controls::ControlValue;
/// `(config, ControlValue)`: write back the value produced by
/// [`controls::Control::apply`] on an option row.
pub(super) type WriteValueFn = fn(&mut Config, controls::ControlValue);

pub(super) struct RowKind {
    pub(super) focusable: bool,
    pub(super) action: RowAction,
    pub(super) read: fn(&Config, &[String]) -> String,
    pub(super) write_string: fn(&mut Config, &str) -> Result<(), String>,
    /// Read the focused row's current value / write a new value as a
    /// normalized [`controls::ControlValue`].  `Some` on option rows
    /// (toggle / pill); `None` on numeric (edit), button, and display-only
    /// rows.  The overlay's input path reads the current value, runs it
    /// through [`controls::Control::apply`], and writes back the result —
    /// so the toggle-flip / pill-cycle math lives in `controls`, not here.
    pub(super) read_value: Option<ReadValueFn>,
    pub(super) write_value: Option<WriteValueFn>,
    /// Control spec for option-style rows: booleans use
    /// [`controls::Control::Toggle`] (the on/off slider) and tri-states use
    /// [`controls::Control::Pill`] over [`controls::ASK_ALWAYS_NEVER`].
    /// When `Some`, the overlay renders the *current* value as that control
    /// (a toggle reads `on`/`off`; a pill matches `read(..)` against its
    /// labels).  When `None`, the row is a single-value display instead
    /// (numeric / path / external-action rows).
    pub(super) options: Option<controls::Control>,
    /// When `Some` and the fn returns true for the current config, the
    /// row is rendered inert (dimmed label + pills) and skipped by focus
    /// navigation / cycling.  Used by the remote-images row, which the
    /// images-`Never` cascade locks to `Never` (mirrors the welcome
    /// modal's cascade — see `ui::welcome`).
    pub(super) disabled: Option<fn(&Config) -> bool>,
}

/// Display string for a boolean setting.  `"on"` is the enabled state, so
/// the [`controls::Control::Toggle`] slider reads it as on.
fn bool_label(value: bool) -> &'static str {
    if value {
        "on"
    } else {
        "off"
    }
}

/// Static table of rows.  `read` formats the field's current value
/// for display; `cycle` is `Some` for fields whose value cycles on
/// Left/Right or Enter (booleans, enum-valued fields, theme name);
/// `write_string` handles the inline-editor confirm path.
pub(super) struct RowDef {
    pub(super) label: &'static str,
    pub(super) description: Option<&'static str>,
    /// Dynamic description override.  When `Some`, it is formatted from
    /// live config and takes precedence over `description` — used to
    /// embed a file-only numeric value (e.g. the blink cadence) in the
    /// pinned footer copy.  Most rows leave this `None`.
    pub(super) describe: Option<fn(&Config) -> String>,
    pub(super) kind: RowKind,
}

impl RowDef {
    /// Resolve the row's footer description for the given config —
    /// dynamic (`describe`) when present, else the static string.
    pub(super) fn resolved_description(&self, config: &Config) -> Option<String> {
        match self.describe {
            Some(f) => Some(f(config)),
            None => self.description.map(|s| s.to_owned()),
        }
    }

    /// Whether this row is currently inert (cascade- or capability-locked).
    pub(super) fn is_disabled(&self, config: &Config) -> bool {
        self.kind.disabled.map(|f| f(config)).unwrap_or(false)
    }

    /// Whether focus may land on this row right now: focusable in
    /// principle and not currently disabled.
    pub(super) fn focus_eligible(&self, config: &Config) -> bool {
        self.kind.focusable && !self.is_disabled(config)
    }
}

fn no_write(_: &mut Config, _: &str) -> Result<(), String> {
    Err("row is not editable in place".to_owned())
}

/// Build a non-focusable display-only row.  Used for the explanatory
/// header note and blank dividers — anything that participates in the
/// row list for layout but never takes focus or fires an action.
fn display_only_row(label: &'static str) -> RowDef {
    RowDef {
        label,
        description: None,
        describe: None,
        kind: RowKind {
            focusable: false,
            action: RowAction::Cycle,
            read: |_, _| String::new(),
            write_string: no_write,
            read_value: None,
            write_value: None,
            options: None,
            disabled: None,
        },
    }
}

fn parse_usize(s: &str) -> Result<usize, String> {
    s.trim()
        .parse::<usize>()
        .map_err(|e| format!("invalid number: {e}"))
}

const IMAGES_ENABLED_ORDER: &[ImagesEnabled] = &[
    ImagesEnabled::Ask,
    ImagesEnabled::Always,
    ImagesEnabled::Never,
];

const DIAGRAMS_ENABLED_ORDER: &[DiagramsEnabled] = &[
    DiagramsEnabled::Ask,
    DiagramsEnabled::Always,
    DiagramsEnabled::Never,
];

const REMOTE_POLICY_ORDER: &[RemoteImagePolicy] = &[
    RemoteImagePolicy::Ask,
    RemoteImagePolicy::Always,
    RemoteImagePolicy::Never,
];

/// Index of `value` within its ordered enum table — the
/// [`controls::ControlValue::Choice`] index fed through
/// [`controls::Control::apply`].  Falls back to 0 for an absent value
/// (unreachable for the tri-states, which list every variant).
fn order_index<T: PartialEq>(order: &[T], value: T) -> usize {
    order.iter().position(|v| *v == value).unwrap_or(0)
}

/// Inverse of [`order_index`]: the value at `i`, clamped to the last entry
/// for an out-of-range index (the pill only ever yields `0..len`).
fn order_value<T: Copy>(order: &[T], i: usize) -> T {
    order[i.min(order.len().saturating_sub(1))]
}

fn images_enabled_label(v: ImagesEnabled) -> &'static str {
    match v {
        ImagesEnabled::Ask => "Ask",
        ImagesEnabled::Always => "Always",
        ImagesEnabled::Never => "Never",
    }
}

fn remote_policy_label(v: RemoteImagePolicy) -> &'static str {
    match v {
        RemoteImagePolicy::Ask => "Ask",
        RemoteImagePolicy::Always => "Always",
        RemoteImagePolicy::Never => "Never",
    }
}

fn parse_images_enabled(s: &str) -> Result<ImagesEnabled, String> {
    match s.trim().to_ascii_lowercase().as_str() {
        "ask" => Ok(ImagesEnabled::Ask),
        "always" => Ok(ImagesEnabled::Always),
        "never" => Ok(ImagesEnabled::Never),
        other => Err(format!("expected Ask/Always/Never, got {other:?}")),
    }
}

fn diagrams_enabled_label(v: DiagramsEnabled) -> &'static str {
    match v {
        DiagramsEnabled::Ask => "Ask",
        DiagramsEnabled::Always => "Always",
        DiagramsEnabled::Never => "Never",
    }
}

fn parse_diagrams_enabled(s: &str) -> Result<DiagramsEnabled, String> {
    match s.trim().to_ascii_lowercase().as_str() {
        "ask" => Ok(DiagramsEnabled::Ask),
        "always" => Ok(DiagramsEnabled::Always),
        "never" => Ok(DiagramsEnabled::Never),
        other => Err(format!("expected Ask/Always/Never, got {other:?}")),
    }
}

fn parse_remote_policy(s: &str) -> Result<RemoteImagePolicy, String> {
    match s.trim().to_ascii_lowercase().as_str() {
        "ask" => Ok(RemoteImagePolicy::Ask),
        "always" => Ok(RemoteImagePolicy::Always),
        "never" => Ok(RemoteImagePolicy::Never),
        other => Err(format!("expected Ask/Always/Never, got {other:?}")),
    }
}

/// Build the static row table.  Order is the user-facing display
/// order; nothing else depends on it.  See [`crate::config::Config`]
/// for each field's persistence semantics.
pub(super) fn build_rows() -> Vec<RowDef> {
    vec![
        display_only_row(HEADER_NOTE),
        display_only_row(""),
        RowDef {
            label: "Open config folder",
            description: Some("\nPress Enter to open in file manager"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::OpenConfigFolder,
                // The folder path is not shown (it can be long); the
                // `[ Open ]` button is the affordance.
                read: |_, _| String::new(),
                write_string: no_write,
                read_value: None,
                write_value: None,
                options: Some(controls::Control::Button("Open")),
                disabled: None,
            },
        },
        RowDef {
            label: "Open config.toml",
            description: Some("\nPress Enter to open in default editor"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::OpenExternalEditor,
                read: |_, _| String::new(),
                write_string: no_write,
                read_value: None,
                write_value: None,
                options: Some(controls::Control::Button("Open")),
                disabled: None,
            },
        },
        // Blank divider — sets the "open externally" pair apart
        // from the editable settings beneath.  Non-focusable so
        // arrow-key navigation skips it; the View renders an empty
        // line for any non-focusable row with an empty label.
        display_only_row(""),
        // ── Editable settings, alphabetical by label, except
        //    `Show line numbers` sits below the two image-visibility
        //    rows so the image group stays contiguous ──
        RowDef {
            label: LABEL_AUTOSAVE,
            description: Some("\nAutomatically save changes when idle"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.autosave_enabled).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.autosave_enabled)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.autosave_enabled = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_BIG_H1,
            description: Some("\nRender H1 titles as large block-character text"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.big_h1).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.big_h1)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.big_h1 = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_BLINK_CURSOR,
            // Static fallback; `describe` embeds the file-only cadence.
            description: Some("\nBlink the editor cursor"),
            describe: Some(|c| format!("\nBlink cursor every {} ms", c.editor.cursor_blink_ms)),
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.cursor_blink).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.cursor_blink)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.cursor_blink = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_CHECK_UPDATES,
            description: Some("\nCheck GitHub for a new release at startup, once a day"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.check_for_updates).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.check_for_updates)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.check_for_updates = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_LIMIT_WIDTH,
            description: Some("\nLimit the editor content width"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.max_width_enabled).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.max_width_enabled)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.max_width_enabled = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: "  Char limit",
            description: Some("\nMaximum content width when limit is on"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Edit,
                read: |c, _| c.editor.max_width_cols.to_string(),
                write_string: |c, v| {
                    let n = parse_usize(v)?;
                    if n < MAX_WIDTH_COLS_MIN {
                        return Err(format!("must be at least {MAX_WIDTH_COLS_MIN}"));
                    }
                    c.editor.max_width_cols = n;
                    Ok(())
                },
                read_value: None,
                write_value: None,
                options: None,
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_SCROLL_SPEED,
            description: Some("\nLines per mouse-wheel tick"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Edit,
                read: |c, _| c.editor.mouse_scroll_lines.to_string(),
                write_string: |c, v| {
                    let n = parse_usize(v)?;
                    if n < MOUSE_SCROLL_LINES_MIN {
                        return Err(format!("must be at least {MOUSE_SCROLL_LINES_MIN}"));
                    }
                    c.editor.mouse_scroll_lines = n;
                    Ok(())
                },
                read_value: None,
                write_value: None,
                options: None,
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_DIFF_ON_CHANGE,
            // Two-line footer description: the on/off meanings differ enough
            // to spell out separately.  Split on `\n` by the footer renderer.
            description: Some(
                "On: Review external changes hunk by hunk\n\
                 Off: Silently reload a clean buffer",
            ),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.diff_on_change).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.diff_on_change)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.diff_on_change = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_SHOW_DIAGRAMS,
            description: Some("\nRender Mermaid code blocks as inline diagrams"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| diagrams_enabled_label(c.diagrams.enabled).to_owned(),
                write_string: |c, v| {
                    c.diagrams.enabled = parse_diagrams_enabled(v)?;
                    Ok(())
                },
                read_value: Some(|c| {
                    controls::ControlValue::Choice(order_index(
                        DIAGRAMS_ENABLED_ORDER,
                        c.diagrams.enabled,
                    ))
                }),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Choice(i) = v {
                        c.diagrams.enabled = order_value(DIAGRAMS_ENABLED_ORDER, i);
                    }
                }),
                options: Some(controls::Control::Pill(controls::ASK_ALWAYS_NEVER)),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_SHOW_IMAGES,
            description: Some("\nShow images in preview and render mode"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| images_enabled_label(c.images.enabled).to_owned(),
                write_string: |c, v| {
                    c.images.enabled = parse_images_enabled(v)?;
                    Ok(())
                },
                read_value: Some(|c| {
                    controls::ControlValue::Choice(order_index(
                        IMAGES_ENABLED_ORDER,
                        c.images.enabled,
                    ))
                }),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Choice(i) = v {
                        c.images.enabled = order_value(IMAGES_ENABLED_ORDER, i);
                    }
                }),
                options: Some(controls::Control::Pill(controls::ASK_ALWAYS_NEVER)),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_SHOW_REMOTE_IMAGES,
            description: Some("\nFetch images from http(s):// URLs"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| remote_policy_label(c.images.remote_policy).to_owned(),
                write_string: |c, v| {
                    c.images.remote_policy = parse_remote_policy(v)?;
                    Ok(())
                },
                read_value: Some(|c| {
                    controls::ControlValue::Choice(order_index(
                        REMOTE_POLICY_ORDER,
                        c.images.remote_policy,
                    ))
                }),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Choice(i) = v {
                        c.images.remote_policy = order_value(REMOTE_POLICY_ORDER, i);
                    }
                }),
                options: Some(controls::Control::Pill(controls::ASK_ALWAYS_NEVER)),
                // Locked to Never (and skipped by focus) while images are
                // off — mirrors the welcome modal's images→remote cascade.
                disabled: Some(|c| matches!(c.images.enabled, ImagesEnabled::Never)),
            },
        },
        RowDef {
            label: LABEL_LINE_NUMBERS,
            description: Some("\nShow line numbers in the left gutter"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.show_line_numbers).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.show_line_numbers)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.show_line_numbers = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_TABLE_BUTTONS,
            description: Some("\nShow table row/column move/resize glyphs"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.table.show_buttons).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.table.show_buttons)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.table.show_buttons = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_SYNTAX_HIGHLIGHTING,
            description: Some("\nColor code blocks using the language on the fence"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.syntax_highlighting).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.syntax_highlighting)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.syntax_highlighting = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_VISUAL_LINE_NAV,
            description: Some("\nUp/Down move by visual lines (vs. logical)"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.visual_line_nav).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.visual_line_nav)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.visual_line_nav = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_VIM_MODE,
            description: Some("\nUse Vim-style modal editing"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                // Vim mode is stored as the modal handler name, not a
                // bool — `read`/`cycle` translate between the
                // `true`/`false` pills and `config.modal.handler`.  The
                // App-level live-update arm rebuilds the VimState so the
                // toggle takes effect without a restart.
                read: |c, _| bool_label(c.modal.handler == VIM_HANDLER).to_owned(),
                write_string: no_write,
                read_value: Some(|c| {
                    controls::ControlValue::Toggle(c.modal.handler == VIM_HANDLER)
                }),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.modal.handler = if b { VIM_HANDLER } else { DEFAULT_HANDLER }.to_owned();
                    }
                }),
                options: Some(controls::Control::Toggle),
                disabled: None,
            },
        },
    ]
}