edamame 0.1.4

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
//! Static row table for the settings overlay.  Each row carries a label, an optional description,
//! and a [`RowKind`] whose function pointers tell the overlay how to read, write, and cycle the
//! underlying config field.  Adding a setting should only touch this file.

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

/// Labels referenced from outside this module are constants so the App-level live-update wiring in
/// `app/modal/settings.rs` can't drift from the row table on a copy change.
///
/// This one is the non-focusable header note, matched by string equality in `build_row_lines` so it
/// renders 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_REFLOW: &str = "Reflow paragraphs";
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 figures";
pub(crate) const LABEL_MATH_PREVIEW: &str = "  Math edit preview";
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`].  Rejecting at the input boundary (rather
/// than relying on the dispatcher's clamp) keeps the persisted value and the live wheel step equal.
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 — hands the path to the OS file manager.
    OpenConfigFolder,
    /// Enter cycles the value (boolean toggle / enum advance).
    Cycle,
    /// Enter opens an inline text editor (numeric field).
    Edit,
}

/// Read an option row's current value as a normalized [`controls::ControlValue`].  Aliased to keep
/// the `Option<…>` fields below under clippy's type-complexity threshold.
pub(super) type ReadValueFn = fn(&Config) -> controls::ControlValue;
/// Write back the value [`controls::Control::apply`] produced for 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 / write the row's value as a [`controls::ControlValue`].  `Some` on option rows
    /// (toggle / pill), `None` on numeric, button, and display-only rows.  The input path routes
    /// the value through [`controls::Control::apply`], so the cycle math lives in `controls`.
    pub(super) read_value: Option<ReadValueFn>,
    pub(super) write_value: Option<WriteValueFn>,
    /// Control spec for option-style rows: booleans use [`controls::Control::Toggle`], tri-states
    /// [`controls::Control::Pill`].  `None` renders the row as a single-value display.
    pub(super) options: Option<controls::Control>,
    /// When it returns true, the row renders inert and focus navigation skips it.  Used by the
    /// remote-images row, which the images-`Never` cascade locks (mirroring `ui::welcome`).
    pub(super) disabled: Option<fn(&Config) -> bool>,
}

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

/// One settings row.  `read` formats the current value for display; `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, formatted from live config and taking precedence over `description` —
    /// used to embed a file-only numeric value (e.g. the blink cadence) in the footer copy.
    pub(super) describe: Option<fn(&Config) -> String>,
    pub(super) kind: RowKind,
}

impl RowDef {
    /// Footer description for `config`: dynamic 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.
    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())
}

/// A non-focusable display-only row: the header note and blank dividers.
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 FIGURES_ENABLED_ORDER: &[FiguresEnabled] = &[
    FiguresEnabled::Ask,
    FiguresEnabled::Always,
    FiguresEnabled::Never,
];

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

/// Index of `value` in its ordered enum table — the [`controls::ControlValue::Choice`] index.
fn order_index<T: PartialEq>(order: &[T], value: T) -> usize {
    order.iter().position(|v| *v == value).unwrap_or(0)
}

/// Inverse of [`order_index`], clamped to the last entry for an out-of-range index.
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: FiguresEnabled) -> &'static str {
    match v {
        FiguresEnabled::Ask => "Ask",
        FiguresEnabled::Always => "Always",
        FiguresEnabled::Never => "Never",
    }
}

fn parse_diagrams_enabled(s: &str) -> Result<FiguresEnabled, String> {
    match s.trim().to_ascii_lowercase().as_str() {
        "ask" => Ok(FiguresEnabled::Ask),
        "always" => Ok(FiguresEnabled::Always),
        "never" => Ok(FiguresEnabled::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.
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 path can be long, so the `[ Open ]` button is the only 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 setting the "open externally" pair apart from the editable settings.
        display_only_row(""),
        // ── Editable settings, alphabetical by label, except `Show line numbers`, which sits
        //    below the 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_REFLOW,
            description: Some("\nReflow soft-wrapped prose paragraphs to the viewport width"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.editor.reflow).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.editor.reflow)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.editor.reflow = 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: the on/off meanings differ enough to spell out separately.
            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 diagrams and $$…$$ math inline"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| diagrams_enabled_label(c.figures.enabled).to_owned(),
                write_string: |c, v| {
                    c.figures.enabled = parse_diagrams_enabled(v)?;
                    Ok(())
                },
                read_value: Some(|c| {
                    controls::ControlValue::Choice(order_index(
                        FIGURES_ENABLED_ORDER,
                        c.figures.enabled,
                    ))
                }),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Choice(i) = v {
                        c.figures.enabled = order_value(FIGURES_ENABLED_ORDER, i);
                    }
                }),
                options: Some(controls::Control::Pill(controls::ASK_ALWAYS_NEVER)),
                disabled: None,
            },
        },
        RowDef {
            label: LABEL_MATH_PREVIEW,
            description: Some("\nEditing a $$…$$ block opens its source below the formula"),
            describe: None,
            kind: RowKind {
                focusable: true,
                action: RowAction::Cycle,
                read: |c, _| bool_label(c.figures.math_preview).to_owned(),
                write_string: no_write,
                read_value: Some(|c| controls::ControlValue::Toggle(c.figures.math_preview)),
                write_value: Some(|c, v| {
                    if let controls::ControlValue::Toggle(b) = v {
                        c.figures.math_preview = b;
                    }
                }),
                options: Some(controls::Control::Toggle),
                // Inert when figures are off: with `[figures].enabled =
                // "never"` no `$$...$$` block is promoted, so there is no
                // reveal for the preview to affect.  Mirrors the
                // remote-images row locking to images-`Never`.
                disabled: Some(|c| matches!(c.figures.enabled, FiguresEnabled::Never)),
            },
        },
        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 while images are off — mirrors the welcome modal's 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, so these translate
                // between the pills and `config.modal.handler`.
                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,
            },
        },
    ]
}