purple-ssh 2.40.0

Open-source terminal SSH manager and SSH config editor. Search hundreds of hosts, sync from 16 clouds, transfer files, manage Docker and Podman over SSH, sign short-lived Vault SSH certs and expose an MCP server for AI agents. Rust TUI, MIT licensed.
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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
use ratatui::Frame;
use ratatui::layout::Alignment;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, BorderType, Clear, Paragraph};
use unicode_width::UnicodeWidthStr;

use super::theme;
use crate::app::App;

// Confirm dialogs are compact modals (y/Esc) with no separate footer row.
// Status messages are not shown here. Any active status will be visible
// once the user closes the dialog and returns to the parent screen.

pub fn render(frame: &mut Frame, _app: &App, alias: &str) {
    let area = super::centered_rect_fixed(52, 7, frame.area());

    // Clear background
    frame.render_widget(Clear, area);

    let block = Block::bordered()
        .border_type(BorderType::Rounded)
        .title(Span::styled(" Confirm Delete ", theme::danger()))
        .border_style(theme::border_danger());

    let text = vec![
        Line::from(""),
        Line::from(Span::styled(
            format!("  Delete \"{}\"?", alias),
            theme::bold(),
        )),
        Line::from(""),
        Line::from(vec![
            Span::styled(" y ", theme::footer_key()),
            Span::styled(" yes ", theme::muted()),
            Span::raw("  "),
            Span::styled(" Esc ", theme::footer_key()),
            Span::styled(" no", theme::muted()),
        ]),
    ];

    let paragraph = Paragraph::new(text).block(block);
    frame.render_widget(paragraph, area);
}

pub fn render_host_key_reset(frame: &mut Frame, _app: &App, hostname: &str) {
    let display = super::truncate(hostname, 40);
    let area = super::centered_rect_fixed(52, 9, frame.area());

    frame.render_widget(Clear, area);

    let block = Block::bordered()
        .border_type(BorderType::Rounded)
        .title(Span::styled(" Host Key Changed ", theme::danger()))
        .border_style(theme::border_danger());

    let text = vec![
        Line::from(""),
        Line::from(Span::styled(
            format!("  Host key for {} changed.", display),
            theme::bold(),
        )),
        Line::from(Span::styled(
            "  This can happen after a server reinstall.",
            theme::muted(),
        )),
        Line::from(Span::styled(
            "  Remove old key and reconnect?",
            theme::muted(),
        )),
        Line::from(""),
        Line::from(vec![
            Span::styled(" y ", theme::footer_key()),
            Span::styled(" yes ", theme::muted()),
            Span::raw("  "),
            Span::styled(" Esc ", theme::footer_key()),
            Span::styled(" no", theme::muted()),
        ]),
    ];

    let paragraph = Paragraph::new(text).block(block);
    frame.render_widget(paragraph, area);
}

pub fn render_confirm_import(frame: &mut Frame, _app: &App, count: usize) {
    let area = super::centered_rect_fixed(52, 7, frame.area());

    frame.render_widget(Clear, area);

    let block = Block::bordered()
        .border_type(BorderType::Rounded)
        .title(Span::styled(" Import ", theme::brand()))
        .border_style(theme::accent());

    let text = vec![
        Line::from(""),
        Line::from(Span::styled(
            format!(
                "  Import {} host{} from known_hosts?",
                count,
                if count == 1 { "" } else { "s" },
            ),
            theme::bold(),
        )),
        Line::from(""),
        Line::from(vec![
            Span::styled(" y ", theme::footer_key()),
            Span::styled(" yes ", theme::muted()),
            Span::raw("  "),
            Span::styled(" Esc ", theme::footer_key()),
            Span::styled(" no", theme::muted()),
        ]),
    ];

    let paragraph = Paragraph::new(text).block(block);
    frame.render_widget(paragraph, area);
}

pub fn render_confirm_purge_stale(
    frame: &mut Frame,
    _app: &App,
    aliases: &[String],
    provider: &Option<String>,
) {
    let count = aliases.len();
    // Show up to 6 host names, then "+N more hosts" (only when N >= 1)
    let max_shown = 6;
    let mut host_lines: Vec<Line> = aliases
        .iter()
        .take(max_shown)
        .map(|a| {
            let truncated = super::truncate(a, 46);
            Line::from(Span::styled(format!("  {}", truncated), theme::muted()))
        })
        .collect();
    if count > max_shown {
        let remaining = count - max_shown;
        host_lines.push(Line::from(Span::styled(
            format!(
                "  +{} more host{}",
                remaining,
                if remaining == 1 { "" } else { "s" }
            ),
            theme::muted(),
        )));
    }

    // height: 2 border + 1 blank + 1 question + host_lines + 1 blank + 1 footer
    let inner_height = 4 + host_lines.len();
    let height = (inner_height + 2) as u16;
    let area = super::centered_rect_fixed(52, height, frame.area());

    frame.render_widget(Clear, area);

    let block = Block::bordered()
        .border_type(BorderType::Rounded)
        .title(Span::styled(" Purge Stale ", theme::danger()))
        .border_style(theme::border_danger());

    let main_line = if let Some(prov) = provider {
        let display = crate::providers::provider_display_name(prov);
        format!(
            "  Remove {} stale {} host{}?",
            count,
            display,
            if count == 1 { "" } else { "s" },
        )
    } else {
        format!(
            "  Remove {} stale host{}?",
            count,
            if count == 1 { "" } else { "s" },
        )
    };

    let mut text = vec![
        Line::from(""),
        Line::from(Span::styled(main_line, theme::bold())),
    ];
    text.extend(host_lines);
    text.push(Line::from(""));
    text.push(Line::from(vec![
        Span::styled(" y ", theme::footer_key()),
        Span::styled(" yes ", theme::muted()),
        Span::raw("  "),
        Span::styled(" Esc ", theme::footer_key()),
        Span::styled(" no", theme::muted()),
    ]));

    let paragraph = Paragraph::new(text).block(block);
    frame.render_widget(paragraph, area);
}

pub fn render_confirm_vault_sign(frame: &mut Frame, _app: &App, signable: &[String]) {
    let count = signable.len();
    // Preview first 5 aliases, append "...and N more" when truncated.
    let preview_limit = 5;
    let shown: Vec<&str> = signable
        .iter()
        .take(preview_limit)
        .map(String::as_str)
        .collect();
    let preview_text = if count > preview_limit {
        format!("  {} ... +{} more", shown.join(", "), count - preview_limit)
    } else if count > 0 {
        format!("  {}", shown.join(", "))
    } else {
        String::new()
    };

    // Height: top + main + blank + preview + blank + note + spacer + footer + bottom = 11
    let height = 11u16;
    let area = super::centered_rect_fixed(72, height, frame.area());

    frame.render_widget(Clear, area);

    let block = Block::bordered()
        .border_type(BorderType::Rounded)
        .title(Span::styled(
            " Sign Vault SSH Certificates ",
            theme::accent(),
        ))
        .border_style(theme::accent());

    let mut footer_spans: Vec<Span<'static>> = Vec::new();
    for s in super::footer_action("y", " confirm ") {
        footer_spans.push(s);
    }
    footer_spans.push(Span::raw("  "));
    for s in super::footer_action("Esc", " cancel") {
        footer_spans.push(s);
    }

    let text = vec![
        Line::from(""),
        Line::from(Span::styled(
            format!(
                "  Sign {} SSH certificate{} via the Vault SSH secrets engine?",
                count,
                if count == 1 { "" } else { "s" },
            ),
            theme::bold(),
        )),
        Line::from(""),
        Line::from(Span::styled(preview_text, theme::muted())),
        Line::from(""),
        Line::from(Span::styled(
            "  Hosts with a still-valid certificate are skipped.".to_string(),
            theme::muted(),
        )),
        Line::from(""),
        Line::from(footer_spans),
    ];

    let paragraph = Paragraph::new(text).block(block);
    frame.render_widget(paragraph, area);
}

/// Block-art logo for the welcome screen (6 lines, ANSI Shadow style).
/// Lines are trimmed; render code pads to max display width for alignment.
const LOGO: [&str; 6] = [
    "\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557} \u{2588}\u{2588}\u{2557}   \u{2588}\u{2588}\u{2557}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557} \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557} \u{2588}\u{2588}\u{2557}     \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557}",
    "\u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2588}\u{2588}\u{2557}\u{2588}\u{2588}\u{2551}   \u{2588}\u{2588}\u{2551}\u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2588}\u{2588}\u{2557}\u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2588}\u{2588}\u{2557}\u{2588}\u{2588}\u{2551}     \u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2550}\u{2550}\u{255D}",
    "\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2554}\u{255D}\u{2588}\u{2588}\u{2551}   \u{2588}\u{2588}\u{2551}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2554}\u{255D}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2554}\u{255D}\u{2588}\u{2588}\u{2551}     \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557}  ",
    "\u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2550}\u{255D} \u{2588}\u{2588}\u{2551}   \u{2588}\u{2588}\u{2551}\u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2588}\u{2588}\u{2557}\u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{2550}\u{255D} \u{2588}\u{2588}\u{2551}     \u{2588}\u{2588}\u{2554}\u{2550}\u{2550}\u{255D}  ",
    "\u{2588}\u{2588}\u{2551}     \u{255A}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2554}\u{255D}\u{2588}\u{2588}\u{2551}  \u{2588}\u{2588}\u{2551}\u{2588}\u{2588}\u{2551}     \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2557}",
    "\u{255A}\u{2550}\u{255D}      \u{255A}\u{2550}\u{2550}\u{2550}\u{2550}\u{2550}\u{255D} \u{255A}\u{2550}\u{255D}  \u{255A}\u{2550}\u{255D}\u{255A}\u{2550}\u{255D}     \u{255A}\u{2550}\u{2550}\u{2550}\u{2550}\u{2550}\u{2550}\u{255D}\u{255A}\u{2550}\u{2550}\u{2550}\u{2550}\u{2550}\u{2550}\u{255D}",
];

/// Typewriter delay: ms after logo reveal before text starts.
const TYPEWRITER_DELAY_MS: u128 = 100;
/// Typewriter speed: ms per character.
const TYPEWRITER_CHAR_MS: u128 = 15;
/// Welcome zoom animation duration (must match ui/mod.rs).
const WELCOME_ZOOM_MS: u128 = 350;
/// Logo line reveal interval (ms between each logo line appearing).
const LOGO_LINE_INTERVAL_MS: u128 = 50;

/// Apply typewriter truncation to a list of spans.
/// Consumes at most `budget` characters across all spans. Returns the truncated
/// spans and a right-pad span so the total width matches the original (stable centering).
fn typewriter_spans<'a>(spans: Vec<Span<'a>>, budget: &mut usize) -> Vec<Span<'a>> {
    let total_chars: usize = spans.iter().map(|s| s.content.chars().count()).sum();
    // Short-circuit: all characters visible, return spans as-is
    if *budget >= total_chars {
        *budget -= total_chars;
        return spans;
    }
    let mut result = Vec::new();
    let mut visible_chars = 0;
    for span in &spans {
        if *budget == 0 {
            break;
        }
        let char_count = span.content.chars().count();
        if char_count <= *budget {
            result.push(span.clone());
            *budget -= char_count;
            visible_chars += char_count;
        } else {
            let truncated: String = span.content.chars().take(*budget).collect();
            visible_chars += *budget;
            result.push(Span::styled(truncated, span.style));
            *budget = 0;
        }
    }
    // Pad to original width for stable centering
    let pad = total_chars.saturating_sub(visible_chars);
    if pad > 0 {
        result.push(Span::raw(" ".repeat(pad)));
    }
    result
}

pub fn render_welcome(
    frame: &mut Frame,
    app: &App,
    has_backup: bool,
    host_count: usize,
    known_hosts_count: usize,
) {
    let has_hosts = host_count > 0;

    // Elapsed time since welcome opened (for phased animation).
    // When welcome_opened is None (e.g. re-render after animation cleared),
    // MAX causes all phases to resolve as "already done" — skipping animation
    // gracefully instead of showing a partially animated state.
    let elapsed = app
        .welcome_opened
        .map(|t| t.elapsed().as_millis())
        .unwrap_or(u128::MAX);

    // Phase 1: Logo lines appear one by one after zoom completes
    let logo_start = WELCOME_ZOOM_MS;
    let logo_lines_visible = if elapsed <= logo_start {
        0usize
    } else {
        (((elapsed - logo_start) / LOGO_LINE_INTERVAL_MS) as usize + 1).min(LOGO.len())
    };

    // Phase 2: Typewriter for text after logo is fully revealed
    let text_start =
        logo_start + (LOGO.len() as u128) * LOGO_LINE_INTERVAL_MS + TYPEWRITER_DELAY_MS;
    let mut char_budget = if elapsed <= text_start {
        0usize
    } else {
        ((elapsed - text_start) / TYPEWRITER_CHAR_MS) as usize
    };

    // Count extra lines for the info section (matches text-building logic below exactly)
    let mut extra = 2usize; // blank + blank between subtitle and hint
    if has_hosts {
        extra += 3; // blank + blank + "N hosts loaded"
    } else if known_hosts_count > 0 {
        extra += 5; // blank + blank + "Found N" + blank + "Press I"
    }
    if has_backup {
        extra += 3; // blank + backup line 1 + line 2
    }

    // Compute logo display width (max across lines) for alignment padding
    let logo_max_w = LOGO
        .iter()
        .map(|l| UnicodeWidthStr::width(*l))
        .max()
        .unwrap_or(0);

    // border(2) + blank(3) + logo(6) + blank(3) + subtitle(1) + hint(1) + blank(1) + footer(1) + blank(3) = 23 base
    let content_height = 23 + extra;
    // Minimum width: fits longest text line ("Your original config has been backed up")
    // with comfortable padding. Logo width + padding, or 56 chars minimum.
    let dialog_width = ((logo_max_w as u16) + 24).max(56);
    let area = super::centered_rect_fixed(dialog_width, content_height as u16, frame.area());

    frame.render_widget(Clear, area);

    let block = Block::bordered()
        .border_type(BorderType::Rounded)
        .border_style(theme::accent());

    // --- Build text lines ---
    let mut text: Vec<Line<'_>> = Vec::new();

    // Top spacing
    text.push(Line::from(""));
    text.push(Line::from(""));
    text.push(Line::from(""));

    // Logo (phased line-by-line reveal, padded to uniform width)
    for (i, logo_line) in LOGO.iter().enumerate() {
        if i < logo_lines_visible {
            let w = UnicodeWidthStr::width(*logo_line);
            let pad = logo_max_w.saturating_sub(w);
            let padded = format!("{}{}", logo_line, " ".repeat(pad));
            text.push(
                Line::from(Span::styled(padded, theme::border_search()))
                    .alignment(Alignment::Center),
            );
        } else {
            text.push(Line::from(""));
        }
    }

    text.push(Line::from(""));
    text.push(Line::from(""));
    text.push(Line::from(""));

    // Subtitle (typewriter)
    let sub_spans = vec![Span::styled(
        "Your SSH config, supercharged.",
        theme::muted(),
    )];
    text.push(
        Line::from(typewriter_spans(sub_spans, &mut char_budget)).alignment(Alignment::Center),
    );
    text.push(Line::from(""));
    text.push(Line::from(""));
    let hint_spans = vec![
        Span::styled("Press ", theme::muted()),
        Span::styled(" ? ", theme::footer_key()),
        Span::styled(" anytime for help.", theme::muted()),
    ];
    text.push(
        Line::from(typewriter_spans(hint_spans, &mut char_budget)).alignment(Alignment::Center),
    );

    // Info lines (typewriter continues)
    if has_hosts {
        text.push(Line::from(""));
        text.push(Line::from(""));
        let info = format!(
            "{} host{} loaded from ~/.ssh/config.",
            host_count,
            if host_count == 1 { "" } else { "s" },
        );
        let spans = vec![Span::styled(info, theme::muted())];
        text.push(
            Line::from(typewriter_spans(spans, &mut char_budget)).alignment(Alignment::Center),
        );
    } else if known_hosts_count > 0 {
        text.push(Line::from(""));
        text.push(Line::from(""));
        let info = format!(
            "Found {} host{} in known_hosts.",
            known_hosts_count,
            if known_hosts_count == 1 { "" } else { "s" },
        );
        let spans = vec![Span::styled(info, theme::muted())];
        text.push(
            Line::from(typewriter_spans(spans, &mut char_budget)).alignment(Alignment::Center),
        );
        text.push(Line::from(""));
        let hint_spans = vec![
            Span::styled("Press ", theme::muted()),
            Span::styled(" I ", theme::footer_key()),
            Span::styled(" to import them.", theme::muted()),
        ];
        text.push(
            Line::from(typewriter_spans(hint_spans, &mut char_budget)).alignment(Alignment::Center),
        );
    }
    if has_backup {
        text.push(Line::from(""));
        let b1 = vec![Span::styled(
            "Your original config has been backed up",
            theme::muted(),
        )];
        text.push(Line::from(typewriter_spans(b1, &mut char_budget)).alignment(Alignment::Center));
        let b2 = vec![Span::styled("to ~/.purple/config.original", theme::muted())];
        text.push(Line::from(typewriter_spans(b2, &mut char_budget)).alignment(Alignment::Center));
    }

    // Footer (appears after all text is typed)
    text.push(Line::from(""));
    if char_budget > 0 {
        text.push(
            Line::from(vec![
                Span::styled(" Enter ", theme::footer_key()),
                Span::styled(" continue", theme::muted()),
            ])
            .alignment(Alignment::Center),
        );
    } else {
        text.push(Line::from(""));
    }
    text.push(Line::from(""));
    text.push(Line::from(""));
    text.push(Line::from(""));

    let paragraph = Paragraph::new(text).block(block);
    frame.render_widget(paragraph, area);
}

/// Compute the welcome dialog height and text line count for testing.
/// Returns (height, text_line_count).
#[cfg(test)]
fn welcome_height_and_lines(
    has_backup: bool,
    host_count: usize,
    known_hosts_count: usize,
) -> (usize, usize) {
    let has_hosts = host_count > 0;
    // Count extra lines (must match render_welcome exactly)
    let mut extra = 2usize; // blank + blank between subtitle and hint
    if has_hosts {
        extra += 3;
    } else if known_hosts_count > 0 {
        extra += 5;
    }
    if has_backup {
        extra += 3;
    }
    let height = 23 + extra;

    // Text lines = height - border(2)
    let lines = height - 2;

    (height, lines)
}

#[cfg(test)]
mod tests {
    use super::*;

    // =========================================================================
    // Welcome dialog height calculation — all 8 permutations
    // =========================================================================
    // (has_hosts, has_backup, known_hosts > 0)
    // Note: when has_hosts=true, known_hosts_count is irrelevant (else-if branch)
    // but we test both 0 and >0 to confirm it doesn't affect height.

    #[test]
    fn welcome_height_hosts_backup_no_known() {
        let (height, lines) = welcome_height_and_lines(true, 5, 0);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=true, has_backup=true, known=0"
        );
    }

    #[test]
    fn welcome_height_hosts_backup_with_known() {
        let (height, lines) = welcome_height_and_lines(true, 5, 10);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=true, has_backup=true, known=10"
        );
    }

    #[test]
    fn welcome_height_hosts_no_backup_no_known() {
        let (height, lines) = welcome_height_and_lines(false, 5, 0);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=true, has_backup=false, known=0"
        );
    }

    #[test]
    fn welcome_height_hosts_no_backup_with_known() {
        let (height, lines) = welcome_height_and_lines(false, 5, 10);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=true, has_backup=false, known=10"
        );
    }

    #[test]
    fn welcome_height_no_hosts_backup_no_known() {
        let (height, lines) = welcome_height_and_lines(true, 0, 0);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=false, has_backup=true, known=0"
        );
    }

    #[test]
    fn welcome_height_no_hosts_backup_with_known() {
        let (height, lines) = welcome_height_and_lines(true, 0, 10);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=false, has_backup=true, known=10"
        );
    }

    #[test]
    fn welcome_height_no_hosts_no_backup_no_known() {
        let (height, lines) = welcome_height_and_lines(false, 0, 0);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=false, has_backup=false, known=0"
        );
    }

    #[test]
    fn welcome_height_no_hosts_no_backup_with_known() {
        let (height, lines) = welcome_height_and_lines(false, 0, 10);
        assert_eq!(
            lines,
            height - 2,
            "has_hosts=false, has_backup=false, known=10"
        );
    }

    // Edge cases for host_count and known_hosts_count boundary values
    #[test]
    fn welcome_height_single_host() {
        let (height, lines) = welcome_height_and_lines(false, 1, 0);
        assert_eq!(lines, height - 2, "single host");
    }

    #[test]
    fn welcome_height_single_known_host() {
        let (height, lines) = welcome_height_and_lines(false, 0, 1);
        assert_eq!(lines, height - 2, "single known_hosts entry");
    }

    // =========================================================================
    // Confirm import dialog pluralization
    // =========================================================================

    #[test]
    fn confirm_import_pluralization_single() {
        let msg = format!(
            "  Import {} host{} from known_hosts?",
            1,
            if 1 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "  Import 1 host from known_hosts?");
    }

    #[test]
    fn confirm_import_pluralization_multiple() {
        let msg = format!(
            "  Import {} host{} from known_hosts?",
            42,
            if 42 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "  Import 42 hosts from known_hosts?");
    }

    // =========================================================================
    // Welcome dialog pluralization
    // =========================================================================

    #[test]
    fn welcome_hosts_pluralization_single() {
        let msg = format!(
            "Found {} host{} in your SSH config.",
            1,
            if 1 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "Found 1 host in your SSH config.");
    }

    #[test]
    fn welcome_hosts_pluralization_multiple() {
        let msg = format!(
            "Found {} host{} in your SSH config.",
            12,
            if 12 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "Found 12 hosts in your SSH config.");
    }

    #[test]
    fn welcome_known_hosts_pluralization_single() {
        let msg = format!(
            "Found {} host{} in known_hosts.",
            1,
            if 1 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "Found 1 host in known_hosts.");
    }

    #[test]
    fn welcome_known_hosts_pluralization_multiple() {
        let msg = format!(
            "Found {} host{} in known_hosts.",
            34,
            if 34 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "Found 34 hosts in known_hosts.");
    }

    #[test]
    fn test_purge_stale_pluralization_single_no_provider() {
        let count = 1;
        let msg = format!(
            "  Remove {} stale host{}?",
            count,
            if count == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "  Remove 1 stale host?");
    }

    #[test]
    fn test_purge_stale_pluralization_multiple_no_provider() {
        let count = 7;
        let msg = format!(
            "  Remove {} stale host{}?",
            count,
            if count == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "  Remove 7 stale hosts?");
    }

    #[test]
    fn test_purge_stale_pluralization_with_provider() {
        let display = "DigitalOcean";
        let count = 3;
        let msg = format!(
            "  Remove {} stale {} host{}?",
            count,
            display,
            if count == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "  Remove 3 stale DigitalOcean hosts?");
    }

    #[test]
    fn test_purge_stale_pluralization_single_with_provider() {
        let display = "Vultr";
        let msg = format!(
            "  Remove {} stale {} host{}?",
            1,
            display,
            if 1 == 1 { "" } else { "s" },
        );
        assert_eq!(msg, "  Remove 1 stale Vultr host?");
    }
}