mnml-rs 0.2.13

A NvChad-style terminal IDE in Rust — vim or standard editing, LSP, git, and an embedded HTTP client.
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
//! The single-line text-input overlay (commit message, …) — a small centered
//! box with a title and one editable line. State lives in `crate::prompt`; key
//! handling lives in `tui.rs`. Records the caret cell in `app.rects.prompt_caret`
//! so `ui::draw` can place the terminal cursor here.
//!
//! Path-typed prompts (`AddWorkspace`) also render a live directory
//! listing below the input — the user can keep typing OR navigate the
//! list with ↑↓, Tab autocompletes, Enter accepts the focused row.

use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Clear, Paragraph};

use crate::app::App;
use crate::ui::theme;

pub fn draw(frame: &mut Frame, app: &mut App, screen: Rect) {
    let Some(p) = &app.prompt else { return };
    // Quit confirm renders as a button dialog — no text input, no
    // submit hint. Kept inside the Prompt state machine because
    // Enter / Esc already route through it; the buttons just pick
    // which action to take on Enter.
    if matches!(p.kind, crate::prompt::PromptKind::QuitConfirm) {
        draw_quit_confirm(frame, app, screen);
        return;
    }
    // #polish 2026-07-06 — DeleteConfirm renders as a two-button
    // `[ Delete ] [ Cancel ]` dialog, replacing the "type the
    // filename to confirm" text-input pattern. Matches the quit
    // dialog's shape so the confirmation-modal primitive reads
    // the same across the app.
    if matches!(p.kind, crate::prompt::PromptKind::DeleteConfirm) {
        draw_delete_confirm(frame, app, screen);
        return;
    }
    // The same button-dialog pattern for every other destructive
    // confirm: git delete branch / stash drop / worktree remove /
    // tag delete / discard hunk / claude kill / merge / rebase.
    if let Some(buttons) = confirm_buttons(&p.kind) {
        draw_generic_confirm(frame, app, screen, buttons);
        return;
    }
    let title = format!(" {} ", p.title);
    let input = p.input.clone();
    let caret_col = p.caret_col();

    // Browse-mode prompts grow taller to fit the directory listing.
    let suggestion_count = p.suggestions.len() as u16;
    let extra_rows = if p.is_path_kind() && suggestion_count > 0 {
        suggestion_count + 1 // suggestions + a thin separator hint
    } else {
        0
    };

    let w = (title.chars().count().max(56) as u16 + 4).min(screen.width.saturating_sub(2));
    // 2026-07-19 — was 5, is 4. Row 0 was `field_y = inner.y + 1`
    // which left a blank line between the title border and the input.
    // User asked to drop it — the compact layout reads cleaner.
    let base_h = 4u16;
    let h = (base_h + extra_rows).min(screen.height.saturating_sub(2));
    let area = Rect {
        x: screen.x + (screen.width.saturating_sub(w)) / 2,
        y: screen.y + (screen.height.saturating_sub(h)) / 3,
        width: w,
        height: h,
    };

    frame.render_widget(Clear, area);
    let block = crate::ui::design_tokens::popup_menu(title);
    let inner = block.inner(area);
    frame.render_widget(block, area);
    if inner.width == 0 || inner.height < 2 {
        return;
    }

    // Place the input directly against the top border. Was
    // `inner.y + 1` (leaving a blank line above the input); user
    // asked to drop that row so the input sits right under the title.
    let field_y = inner.y;
    let pad = 1u16;
    let avail = inner.width.saturating_sub(pad) as usize;
    let chars: Vec<char> = input.chars().collect();
    let start = caret_col.saturating_sub(avail.saturating_sub(1));
    let shown: String = chars.iter().skip(start).take(avail).collect();
    // Placeholder shown when the input is empty — dimmed hint that
    // clears on the first keystroke. Mirrors browser address-bar
    // + Bruno URL-field semantics. Kind-driven so different prompts
    // can carry different hints without special-casing at the callsite.
    let placeholder_span = if input.is_empty() {
        placeholder_for(&p.kind).map(|hint| {
            Span::styled(
                hint,
                Style::default()
                    .fg(theme::cur().comment)
                    .bg(theme::cur().bg2)
                    .add_modifier(Modifier::ITALIC),
            )
        })
    } else {
        None
    };
    let line = if let Some(ph) = placeholder_span {
        Line::from(vec![ph])
    } else {
        Line::from(Span::styled(
            shown,
            Style::default().fg(theme::cur().fg).bg(theme::cur().bg2),
        ))
    };
    frame.render_widget(
        Paragraph::new(line).style(Style::default().bg(theme::cur().bg2)),
        Rect::new(inner.x + pad, field_y, inner.width.saturating_sub(pad), 1),
    );

    // Hint row.
    let hint_y = field_y + 1;
    let hint = if p.is_path_kind() && !p.suggestions.is_empty() {
        "  enter submit · ↑↓ browse · tab complete · esc cancel"
    } else if p.is_path_kind() {
        "  enter submit · type to browse · esc cancel"
    } else {
        "  enter to submit · esc to cancel"
    };
    if hint_y < inner.y + inner.height {
        frame.render_widget(
            Paragraph::new(Line::from(Span::styled(
                hint,
                Style::default()
                    .fg(theme::cur().comment)
                    .bg(theme::cur().bg2),
            ))),
            Rect::new(inner.x, hint_y, inner.width, 1),
        );
    }

    // Suggestion list (path-typed prompts only). Each row shows the
    // full path with the parent dim and the basename bold; the focused
    // row gets a cyan background highlight.
    if p.is_path_kind() && !p.suggestions.is_empty() {
        let list_top = hint_y + 1;
        for (i, path) in p.suggestions.iter().enumerate() {
            let y = list_top + i as u16;
            if y >= inner.y + inner.height {
                break;
            }
            let focused = p.selected_suggestion == Some(i);
            let row_rect = Rect::new(inner.x, y, inner.width, 1);
            let (parent, name) = split_for_display(path);
            // Focused row uses the menu-family highlight (cyan bg,
            // bg_dark fg); unfocused rows match the panel's own bg2.
            let bg = if focused {
                theme::cur().cyan
            } else {
                theme::cur().bg2
            };
            let fg_main = if focused {
                theme::cur().bg_dark
            } else {
                theme::cur().fg
            };
            let cursor = if focused { "" } else { " " };
            let line = Line::from(vec![
                Span::styled(format!(" {cursor} "), Style::default().fg(fg_main).bg(bg)),
                Span::styled(
                    parent,
                    Style::default()
                        .fg(if focused {
                            theme::cur().bg_dark
                        } else {
                            theme::cur().comment
                        })
                        .bg(bg),
                ),
                Span::styled(
                    name,
                    Style::default()
                        .fg(fg_main)
                        .bg(bg)
                        .add_modifier(if focused {
                            Modifier::BOLD
                        } else {
                            Modifier::empty()
                        }),
                ),
            ]);
            frame.render_widget(
                Paragraph::new(line).style(Style::default().bg(bg)),
                row_rect,
            );
        }
    }

    let cx = inner.x + pad + (caret_col - start) as u16;
    app.rects.prompt_caret = Some((cx.min(inner.x + inner.width.saturating_sub(1)), field_y));
}

/// Quit-confirm buttons. Order matches `App::quit_prompt_buttons()`;
/// the u8 payload is what `App::run_quit_button` dispatches on.
pub const QUIT_BTN_SAVE_ALL: u8 = 0;
pub const QUIT_BTN_QUIT_ANYWAY: u8 = 1;
pub const QUIT_BTN_CANCEL: u8 = 2;
pub const QUIT_BTN_QUIT_CLEAN: u8 = 3;

/// Delete-confirm buttons. Order matches the Vec returned by
/// `delete_buttons`; the u8 payload is what `App::run_delete_button`
/// dispatches on.
pub const CONFIRM_BTN_PRIMARY: u8 = 0;
pub const CONFIRM_BTN_CANCEL: u8 = 1;

/// Two-button set for the delete-confirm dialog. Returns
/// `(label, action_code, hotkey_char_idx)` per button. Cancel is the
/// default focus (safety first) — see `open_fs_delete_prompt`.
pub fn delete_buttons() -> Vec<(&'static str, u8, usize)> {
    vec![
        ("  Delete  ", CONFIRM_BTN_PRIMARY, 2),
        (" Cancel ", CONFIRM_BTN_CANCEL, 1),
    ]
}

/// Button set for the current dirty state — driven by [`App::dirty_buffer_names`].
/// Returns `(label, action_code, hotkey_char_idx)` per button.
pub fn quit_buttons(has_dirty: bool) -> Vec<(&'static str, u8, usize)> {
    if has_dirty {
        vec![
            ("  Save all  ", QUIT_BTN_SAVE_ALL, 2),
            (" Quit anyway ", QUIT_BTN_QUIT_ANYWAY, 1),
            (" Cancel ", QUIT_BTN_CANCEL, 1),
        ]
    } else {
        vec![
            ("  Quit  ", QUIT_BTN_QUIT_CLEAN, 2),
            (" Cancel ", QUIT_BTN_CANCEL, 1),
        ]
    }
}

fn draw_quit_confirm(frame: &mut Frame, app: &mut App, screen: Rect) {
    let Some(p) = &app.prompt else { return };
    let dirty = app.dirty_buffer_names();
    let has_dirty = !dirty.is_empty();
    let buttons = quit_buttons(has_dirty);
    let selected = p.cursor.min(buttons.len().saturating_sub(1));

    let title = p.title.clone();
    let msg = if has_dirty {
        format!("  Unsaved: {}", dirty.join(", "))
    } else {
        "  This will close mnml.".to_string()
    };

    let buttons_w: usize = buttons.iter().map(|(l, _, _)| l.chars().count() + 1).sum();
    let inner_w = msg
        .chars()
        .count()
        .max(buttons_w + 2)
        .max(title.chars().count() + 4)
        .max(32);
    let w = (inner_w as u16 + 2).min(screen.width.saturating_sub(2));
    // 3 rows of content: message + blank + buttons. +2 for borders.
    let h = 5u16.min(screen.height.saturating_sub(2));
    let area = Rect {
        x: screen.x + (screen.width.saturating_sub(w)) / 2,
        y: screen.y + (screen.height.saturating_sub(h)) / 3,
        width: w,
        height: h,
    };

    frame.render_widget(Clear, area);
    let block = crate::ui::design_tokens::popup_menu(format!(" {title} "));
    let inner = block.inner(area);
    frame.render_widget(block, area);
    if inner.width == 0 || inner.height < 2 {
        return;
    }

    // Row 0: the message. Fill to inner width so the panel bg reads clean.
    let msg_padded = format!("{msg:<width$}", width = inner.width as usize);
    frame.render_widget(
        Paragraph::new(Line::from(Span::styled(
            msg_padded,
            Style::default().fg(theme::cur().fg).bg(theme::cur().bg2),
        ))),
        Rect::new(inner.x, inner.y, inner.width, 1),
    );

    // Last inner row: right-aligned buttons. Focused button gets the
    // menu-family highlight (cyan + bg_dark + bold) so it reads as the
    // same primitive as menu bar / context menu selection.
    let by = inner.y + inner.height - 1;
    let total_bw: u16 = buttons
        .iter()
        .map(|(l, _, _)| l.chars().count() as u16 + 1)
        .sum();
    let mut bx = inner.x + inner.width.saturating_sub(total_bw);
    app.rects.quit_prompt_buttons.clear();
    for (i, (label, code, hk_idx)) in buttons.iter().enumerate() {
        let focused = i == selected;
        let style = if focused {
            crate::ui::design_tokens::row_highlight_menu()
        } else {
            crate::ui::design_tokens::row_plain_menu()
        };
        let bw = label.chars().count() as u16;
        if bx + bw > inner.x + inner.width {
            break;
        }
        // Split so the hotkey letter is underlined.
        let chars: Vec<char> = label.chars().collect();
        let mut spans: Vec<Span> = Vec::new();
        spans.push(Span::styled(
            chars[..*hk_idx].iter().collect::<String>(),
            style,
        ));
        if let Some(&hk) = chars.get(*hk_idx) {
            spans.push(Span::styled(
                hk.to_string(),
                style.add_modifier(Modifier::UNDERLINED),
            ));
        }
        spans.push(Span::styled(
            chars[(hk_idx + 1)..].iter().collect::<String>(),
            style,
        ));
        let rect = Rect::new(bx, by, bw, 1);
        frame.render_widget(Paragraph::new(Line::from(spans)), rect);
        app.rects.quit_prompt_buttons.push((rect, *code));
        bx += bw + 1;
    }
}

/// #polish 2026-07-06 — for any destructive confirm-style PromptKind
/// (git delete branch / stash drop / worktree remove / tag delete /
/// hunk discard / claude kill / merge / rebase), return the
/// `[ primary_label, cancel_label ]` pair for a two-button dialog.
/// Returns `None` for other kinds (regular text-input prompts).
///
/// Rendering + key/mouse dispatch checks this table to decide
/// whether to draw the standard input field or a button dialog.
pub fn confirm_labels(kind: &crate::prompt::PromptKind) -> Option<(&'static str, &'static str)> {
    use crate::prompt::PromptKind::*;
    Some(match kind {
        GitDeleteBranchConfirm => ("  Delete  ", " Cancel "),
        WorktreeRemoveConfirm => ("  Remove  ", " Cancel "),
        GitStashDrop => ("  Drop  ", " Cancel "),
        GitTagDelete => ("  Delete  ", " Cancel "),
        DiffDiscardHunk | GitDiscardFile => ("  Discard  ", " Cancel "),
        ClaudeKillConfirm => ("  Kill  ", " Cancel "),
        GitMergeConfirm => ("  Merge  ", " Cancel "),
        GitRebaseConfirm => ("  Rebase  ", " Cancel "),
        TreeMoveConfirm => ("  Move  ", " Cancel "),
        AiToolConfirm => ("  Allow  ", " Deny "),
        ToolInstallConfirm | MarketplaceInstallConfirm => ("  Install  ", " Cancel "),
        IntegrationRemoveConfirm => ("  Uninstall  ", " Cancel "),
        ResetToDefaultsConfirm => ("  Reset  ", " Cancel "),
        PortableChoicePrompt => ("  Portable  ", "  Normal  "),
        _ => return None,
    })
}

/// Buttons for a generic confirm dialog — matches the shape of
/// `quit_buttons` / `delete_buttons`. Underscored hotkey char is
/// the third field (`d` for Delete, `c` for Cancel, etc.).
pub fn confirm_buttons(kind: &crate::prompt::PromptKind) -> Option<Vec<(&'static str, u8, usize)>> {
    let (primary, cancel) = confirm_labels(kind)?;
    // Hotkey index — pick the first alpha char in each label.
    let hk = |label: &str| {
        label
            .char_indices()
            .find(|(_, c)| c.is_ascii_alphabetic())
            .map(|(i, _)| i)
            .unwrap_or(0)
    };
    Some(vec![
        (primary, CONFIRM_BTN_PRIMARY, hk(primary)),
        (cancel, CONFIRM_BTN_CANCEL, hk(cancel)),
    ])
}

/// #polish 2026-07-06 — DeleteConfirm dialog. Two buttons
/// `[ Delete ] [ Cancel ]`; Cancel is the default focus. The title
/// text is the full "Delete <rel> (N entries)" string prepared by
/// `open_fs_delete_prompt`.
fn draw_delete_confirm(frame: &mut Frame, app: &mut App, screen: Rect) {
    let Some(p) = &app.prompt else { return };
    let buttons = delete_buttons();
    let selected = p.cursor.min(buttons.len().saturating_sub(1));
    let title = p.title.clone();

    let buttons_w: usize = buttons.iter().map(|(l, _, _)| l.chars().count() + 1).sum();
    let inner_w = title.chars().count().max(buttons_w + 2).max(40);
    let w = (inner_w as u16 + 2).min(screen.width.saturating_sub(2));
    let h = 5u16.min(screen.height.saturating_sub(2));
    let area = Rect {
        x: screen.x + (screen.width.saturating_sub(w)) / 2,
        y: screen.y + (screen.height.saturating_sub(h)) / 3,
        width: w,
        height: h,
    };

    frame.render_widget(Clear, area);
    let block = crate::ui::design_tokens::popup_menu(" Delete ");
    let inner = block.inner(area);
    frame.render_widget(block, area);
    if inner.width == 0 || inner.height < 2 {
        return;
    }

    // Row 0: the title (which contains the file name + entry count).
    let msg_padded = format!(
        " {title:<width$}",
        width = (inner.width as usize).saturating_sub(1)
    );
    frame.render_widget(
        Paragraph::new(Line::from(Span::styled(
            msg_padded,
            Style::default().fg(theme::cur().fg).bg(theme::cur().bg2),
        ))),
        Rect::new(inner.x, inner.y, inner.width, 1),
    );

    // Last inner row: right-aligned buttons.
    let by = inner.y + inner.height - 1;
    let total_bw: u16 = buttons
        .iter()
        .map(|(l, _, _)| l.chars().count() as u16 + 1)
        .sum();
    let mut bx = inner.x + inner.width.saturating_sub(total_bw);
    app.rects.confirm_dialog_buttons.clear();
    for (i, (label, code, hk_idx)) in buttons.iter().enumerate() {
        let focused = i == selected;
        let style = if focused {
            crate::ui::design_tokens::row_highlight_menu()
        } else {
            crate::ui::design_tokens::row_plain_menu()
        };
        let bw = label.chars().count() as u16;
        if bx + bw > inner.x + inner.width {
            break;
        }
        let chars: Vec<char> = label.chars().collect();
        let mut spans: Vec<Span> = Vec::new();
        spans.push(Span::styled(
            chars[..*hk_idx].iter().collect::<String>(),
            style,
        ));
        if let Some(&hk) = chars.get(*hk_idx) {
            spans.push(Span::styled(
                hk.to_string(),
                style.add_modifier(Modifier::UNDERLINED),
            ));
        }
        spans.push(Span::styled(
            chars[(hk_idx + 1)..].iter().collect::<String>(),
            style,
        ));
        let rect = Rect::new(bx, by, bw, 1);
        frame.render_widget(Paragraph::new(Line::from(spans)), rect);
        app.rects.confirm_dialog_buttons.push((rect, *code));
        bx += bw + 1;
    }
}

/// Generic two-button confirm dialog — used by every destructive
/// PromptKind whose accept handler used to gate on a "type X to
/// confirm" magic string. The primary button label + hotkey come
/// from `confirm_buttons(kind)`; the title text is
/// `Prompt.title` (already set by the opening code).
fn draw_generic_confirm(
    frame: &mut Frame,
    app: &mut App,
    screen: Rect,
    buttons: Vec<(&'static str, u8, usize)>,
) {
    let Some(p) = &app.prompt else { return };
    let selected = p.cursor.min(buttons.len().saturating_sub(1));
    let title = p.title.clone();

    let buttons_w: usize = buttons.iter().map(|(l, _, _)| l.chars().count() + 1).sum();
    let inner_w = title.chars().count().max(buttons_w + 2).max(40);
    let w = (inner_w as u16 + 2).min(screen.width.saturating_sub(2));
    let h = 5u16.min(screen.height.saturating_sub(2));
    let area = Rect {
        x: screen.x + (screen.width.saturating_sub(w)) / 2,
        y: screen.y + (screen.height.saturating_sub(h)) / 3,
        width: w,
        height: h,
    };
    frame.render_widget(Clear, area);
    let block = crate::ui::design_tokens::popup_menu(" Confirm ");
    let inner = block.inner(area);
    frame.render_widget(block, area);
    if inner.width == 0 || inner.height < 2 {
        return;
    }
    let msg_padded = format!(
        " {title:<width$}",
        width = (inner.width as usize).saturating_sub(1)
    );
    frame.render_widget(
        Paragraph::new(Line::from(Span::styled(
            msg_padded,
            Style::default().fg(theme::cur().fg).bg(theme::cur().bg2),
        ))),
        Rect::new(inner.x, inner.y, inner.width, 1),
    );
    let by = inner.y + inner.height - 1;
    let total_bw: u16 = buttons
        .iter()
        .map(|(l, _, _)| l.chars().count() as u16 + 1)
        .sum();
    let mut bx = inner.x + inner.width.saturating_sub(total_bw);
    app.rects.confirm_dialog_buttons.clear();
    for (i, (label, code, hk_idx)) in buttons.iter().enumerate() {
        let focused = i == selected;
        let style = if focused {
            crate::ui::design_tokens::row_highlight_menu()
        } else {
            crate::ui::design_tokens::row_plain_menu()
        };
        let bw = label.chars().count() as u16;
        if bx + bw > inner.x + inner.width {
            break;
        }
        let chars: Vec<char> = label.chars().collect();
        let mut spans: Vec<Span> = Vec::new();
        spans.push(Span::styled(
            chars[..*hk_idx].iter().collect::<String>(),
            style,
        ));
        if let Some(&hk) = chars.get(*hk_idx) {
            spans.push(Span::styled(
                hk.to_string(),
                style.add_modifier(Modifier::UNDERLINED),
            ));
        }
        spans.push(Span::styled(
            chars[(hk_idx + 1)..].iter().collect::<String>(),
            style,
        ));
        let rect = Rect::new(bx, by, bw, 1);
        frame.render_widget(Paragraph::new(Line::from(spans)), rect);
        app.rects.confirm_dialog_buttons.push((rect, *code));
        bx += bw + 1;
    }
}

/// Dimmed placeholder hint for empty prompt inputs. Mirrors browser
/// address-bar + Bruno URL-field semantics — clears on first keystroke.
fn placeholder_for(kind: &crate::prompt::PromptKind) -> Option<&'static str> {
    use crate::prompt::PromptKind::*;
    match kind {
        BrowserUrl => Some("https://example.com"),
        LinkClaudeToken => Some("Ctrl+K: auto-fetch from macOS Keychain"),
        _ => None,
    }
}

/// Split a path into a dimmed parent prefix (with trailing `/`) and
/// the basename for highlighted rendering.
fn split_for_display(p: &std::path::Path) -> (String, String) {
    let parent = p
        .parent()
        .map(|q| {
            let mut s = q.to_string_lossy().to_string();
            if !s.ends_with('/') {
                s.push('/');
            }
            s
        })
        .unwrap_or_default();
    let name = p
        .file_name()
        .map(|s| s.to_string_lossy().to_string())
        .unwrap_or_default();
    (parent, name)
}