Skip to main content

purple_ssh/
messages.rs

1//! Centralized user-facing messages.
2//!
3//! Every string the user can see (toasts, CLI output, error messages) lives
4//! here. Handler, CLI and UI code reference these constants and functions
5//! instead of inlining string literals. This makes copy consistent, auditable
6//! and future-proof for i18n.
7
8// ── General / shared ────────────────────────────────────────────────
9
10pub const FAILED_TO_SAVE: &str = "Failed to save";
11pub fn failed_to_save(e: &impl std::fmt::Display) -> String {
12    format!("{}: {}", FAILED_TO_SAVE, e)
13}
14
15pub const CONFIG_CHANGED_EXTERNALLY: &str =
16    "Config changed externally. Press Esc and re-open to pick up changes.";
17
18// ── Demo mode ───────────────────────────────────────────────────────
19
20pub const DEMO_CONNECTION_DISABLED: &str = "Demo mode. Connection disabled.";
21pub const DEMO_SYNC_DISABLED: &str = "Demo mode. Sync disabled.";
22pub const DEMO_TUNNELS_DISABLED: &str = "Demo mode. Tunnels disabled.";
23pub const DEMO_VAULT_SIGNING_DISABLED: &str = "Demo mode. Vault SSH signing disabled.";
24pub const DEMO_FILE_BROWSER_DISABLED: &str = "Demo mode. File browser disabled.";
25pub const DEMO_CONTAINER_REFRESH_DISABLED: &str = "Demo mode. Container refresh disabled.";
26pub const DEMO_CONTAINER_ACTIONS_DISABLED: &str = "Demo mode. Container actions disabled.";
27pub const DEMO_EXECUTION_DISABLED: &str = "Demo mode. Execution disabled.";
28pub const DEMO_PROVIDER_CHANGES_DISABLED: &str = "Demo mode. Provider config changes disabled.";
29
30// ── Stale host ──────────────────────────────────────────────────────
31
32pub fn stale_host(hint: &str) -> String {
33    format!("Stale host.{}", hint)
34}
35
36// ── Host list ───────────────────────────────────────────────────────
37
38pub fn copied_ssh_command(alias: &str) -> String {
39    format!("Copied SSH command for {}.", alias)
40}
41
42pub fn copied_config_block(alias: &str) -> String {
43    format!("Copied config block for {}.", alias)
44}
45
46pub fn showing_unreachable(count: usize) -> String {
47    format!(
48        "Showing {} unreachable host{}.",
49        count,
50        if count == 1 { "" } else { "s" }
51    )
52}
53
54pub fn sorted_by(label: &str) -> String {
55    format!("Sorted by {}.", label)
56}
57
58pub fn sorted_by_save_failed(label: &str, e: &impl std::fmt::Display) -> String {
59    format!("Sorted by {}. (save failed: {})", label, e)
60}
61
62pub fn grouped_by(label: &str) -> String {
63    format!("Grouped by {}.", label)
64}
65
66pub fn grouped_by_save_failed(label: &str, e: &impl std::fmt::Display) -> String {
67    format!("Grouped by {}. (save failed: {})", label, e)
68}
69
70pub const UNGROUPED: &str = "Ungrouped.";
71
72pub fn ungrouped_save_failed(e: &impl std::fmt::Display) -> String {
73    format!("Ungrouped. (save failed: {})", e)
74}
75
76pub const GROUPED_BY_TAG: &str = "Grouped by tag.";
77
78pub fn grouped_by_tag_save_failed(e: &impl std::fmt::Display) -> String {
79    format!("Grouped by tag. (save failed: {})", e)
80}
81
82pub fn host_restored(alias: &str) -> String {
83    format!("{} is back from the dead.", alias)
84}
85
86pub fn restored_tags(count: usize) -> String {
87    format!(
88        "Restored tags on {} host{}.",
89        count,
90        if count == 1 { "" } else { "s" }
91    )
92}
93
94pub const NOTHING_TO_UNDO: &str = "Nothing to undo.";
95pub const NO_IMPORTABLE_HOSTS: &str = "No importable hosts in known_hosts.";
96pub const NO_STALE_HOSTS: &str = "No stale hosts.";
97pub const NO_HOST_SELECTED: &str = "No host selected.";
98pub const NO_HOSTS_TO_RUN: &str = "No hosts to run on.";
99pub const NO_HOSTS_TO_TAG: &str = "No hosts to tag.";
100pub const PING_FIRST: &str = "Ping first (p/P), then filter with !.";
101pub const PINGING_ALL: &str = "Pinging all the things...";
102
103pub fn included_file_edit(name: &str) -> String {
104    format!("{} is in an included file. Edit it there.", name)
105}
106
107pub fn included_file_delete(name: &str) -> String {
108    format!("{} is in an included file. Delete it there.", name)
109}
110
111pub fn included_file_clone(name: &str) -> String {
112    format!("{} is in an included file. Clone it there.", name)
113}
114
115pub fn included_host_lives_in(alias: &str, path: &impl std::fmt::Display) -> String {
116    format!("{} lives in {}. Edit it there.", alias, path)
117}
118
119pub fn included_host_clone_there(alias: &str, path: &impl std::fmt::Display) -> String {
120    format!("{} lives in {}. Clone it there.", alias, path)
121}
122
123pub fn included_host_tag_there(alias: &str, path: &impl std::fmt::Display) -> String {
124    format!("{} is included from {}. Tag it there.", alias, path)
125}
126
127pub const HOST_NOT_FOUND_IN_CONFIG: &str = "Host not found in config.";
128
129// ── Host form ───────────────────────────────────────────────────────
130
131pub const SMART_PARSED: &str = "Smart-parsed that for you. Check the fields.";
132pub const LOOKS_LIKE_ADDRESS: &str = "Looks like an address. Suggested as Host.";
133
134// ── Confirm delete ──────────────────────────────────────────────────
135
136pub fn goodbye_host(alias: &str) -> String {
137    format!("Goodbye, {}. We barely knew ye. (u to undo)", alias)
138}
139
140pub fn host_not_found(alias: &str) -> String {
141    format!("Host '{}' not found.", alias)
142}
143
144/// Toast after stripping an alias token from a shared `Host` line. Undo is
145/// not offered because re-inserting a whole block would not reverse a token
146/// strip (sibling aliases and their directives stay in place).
147pub fn siblings_stripped(alias: &str, sibling_count: usize) -> String {
148    if sibling_count == 1 {
149        format!(
150            "Stripped {}. 1 sibling alias kept its shared config.",
151            alias
152        )
153    } else {
154        format!(
155            "Stripped {}. {} sibling aliases kept their shared config.",
156            alias, sibling_count
157        )
158    }
159}
160
161/// One-line note rendered inside the confirm-delete dialog when the target
162/// alias shares its `Host` block with siblings. Explains that the other
163/// tokens survive.
164pub fn confirm_delete_siblings_note(siblings: &[String]) -> String {
165    let shown: Vec<&str> = siblings.iter().take(3).map(String::as_str).collect();
166    let tail = if siblings.len() > shown.len() {
167        format!(" +{} more", siblings.len() - shown.len())
168    } else {
169        String::new()
170    };
171    format!("Siblings kept: {}{}", shown.join(", "), tail)
172}
173
174pub fn cert_cleanup_warning(path: &impl std::fmt::Display, e: &impl std::fmt::Display) -> String {
175    format!("Warning: failed to clean up Vault SSH cert {}: {}", path, e)
176}
177
178// ── Clone ───────────────────────────────────────────────────────────
179
180pub const CLONED_VAULT_CLEARED: &str = "Cloned. Vault SSH role cleared on copy.";
181
182// ── Tunnels ─────────────────────────────────────────────────────────
183
184pub const TUNNEL_REMOVED: &str = "Tunnel removed.";
185pub const TUNNEL_SAVED: &str = "Tunnel saved.";
186pub const TUNNEL_NOT_FOUND: &str = "Tunnel not found in config.";
187pub const TUNNEL_INCLUDED_READ_ONLY: &str = "Included host. Tunnels are read-only.";
188pub const TUNNEL_ORIGINAL_NOT_FOUND: &str = "Original tunnel not found in config.";
189pub const TUNNEL_LIST_CHANGED: &str = "Tunnel list changed externally. Press Esc and re-open.";
190pub const TUNNEL_DUPLICATE: &str = "Duplicate tunnel already configured.";
191
192pub fn tunnel_stopped(alias: &str) -> String {
193    format!("Tunnel for {} stopped.", alias)
194}
195
196pub fn tunnel_started(alias: &str) -> String {
197    format!("Tunnel for {} started.", alias)
198}
199
200pub fn tunnel_start_failed(e: &impl std::fmt::Display) -> String {
201    format!("Failed to start tunnel: {}", e)
202}
203
204// ── Ping ────────────────────────────────────────────────────────────
205
206pub fn pinging_host(alias: &str, show_hint: bool) -> String {
207    if show_hint {
208        format!("Pinging {}... (Shift+P pings all)", alias)
209    } else {
210        format!("Pinging {}...", alias)
211    }
212}
213
214pub fn bastion_not_found(alias: &str) -> String {
215    format!("Bastion {} not found in config.", alias)
216}
217
218// ── Providers ───────────────────────────────────────────────────────
219
220pub fn provider_removed(display_name: &str) -> String {
221    format!(
222        "Removed {} configuration. Synced hosts remain in your SSH config.",
223        display_name
224    )
225}
226
227pub fn provider_not_configured(display_name: &str) -> String {
228    format!("{} is not configured. Nothing to remove.", display_name)
229}
230
231pub fn provider_configure_first(display_name: &str) -> String {
232    format!("Configure {} first. Press Enter to set up.", display_name)
233}
234
235pub fn provider_saved_syncing(display_name: &str) -> String {
236    format!("Saved {} configuration. Syncing...", display_name)
237}
238
239pub fn provider_saved(display_name: &str) -> String {
240    format!("Saved {} configuration.", display_name)
241}
242
243pub fn no_stale_hosts_for(display_name: &str) -> String {
244    format!("No stale hosts for {}.", display_name)
245}
246
247pub fn contains_control_chars(name: &str) -> String {
248    format!("{} contains control characters.", name)
249}
250
251pub const TOKEN_FORMAT_AWS: &str = "Token format: AccessKeyId:SecretAccessKey";
252pub const URL_REQUIRED_PROXMOX: &str = "URL is required for Proxmox VE.";
253pub const PROJECT_REQUIRED_GCP: &str = "Project ID can't be empty. Set your GCP project ID.";
254pub const COMPARTMENT_REQUIRED_OCI: &str =
255    "Compartment can't be empty. Set your OCI compartment OCID.";
256pub const REGIONS_REQUIRED_AWS: &str = "Select at least one AWS region.";
257pub const ZONES_REQUIRED_SCALEWAY: &str = "Select at least one Scaleway zone.";
258pub const SUBSCRIPTIONS_REQUIRED_AZURE: &str = "Enter at least one Azure subscription ID.";
259pub const ALIAS_PREFIX_INVALID: &str =
260    "Alias prefix can't contain spaces or pattern characters (*, ?, [, !).";
261pub const USER_NO_WHITESPACE: &str = "User can't contain whitespace.";
262pub const VAULT_ROLE_FORMAT: &str = "Vault SSH role must be in the form <mount>/sign/<role>.";
263
264// ── Vault SSH ───────────────────────────────────────────────────────
265
266pub const VAULT_SIGNING_CANCELLED: &str = "Vault SSH signing cancelled.";
267pub const VAULT_NO_ROLE_CONFIGURED: &str = "No Vault SSH role configured. Set one in the host form \
268     (Vault SSH role field) or on a provider for shared defaults.";
269pub const VAULT_NO_HOSTS_WITH_ROLE: &str = "No hosts with a Vault SSH role configured.";
270pub const VAULT_ALL_CERTS_VALID: &str = "All Vault SSH certificates are still valid.";
271pub const VAULT_NO_ADDRESS: &str = "No Vault address set. Edit the host (e) or provider \
272     and fill in the Vault SSH Address field.";
273
274pub fn vault_error(msg: &str) -> String {
275    format!("Vault SSH: {}", msg)
276}
277
278pub fn vault_signed(alias: &str) -> String {
279    format!("Signed Vault SSH cert for {}", alias)
280}
281
282pub fn vault_sign_failed(alias: &str, message: &str) -> String {
283    format!("Vault SSH: failed to sign {}: {}", alias, message)
284}
285
286pub fn vault_signing_progress(spinner: &str, done: usize, total: usize, alias: &str) -> String {
287    format!(
288        "{} Signing {}/{}: {} (V to cancel)",
289        spinner, done, total, alias
290    )
291}
292
293pub fn vault_cert_saved_host_gone(alias: &str) -> String {
294    format!(
295        "Vault SSH cert saved for {} but host no longer in config \
296         (renamed or deleted). CertificateFile NOT written.",
297        alias
298    )
299}
300
301pub fn vault_spawn_failed(e: &impl std::fmt::Display) -> String {
302    format!("Vault SSH: failed to spawn signing thread: {}", e)
303}
304
305pub fn vault_cert_check_failed(alias: &str, message: &str) -> String {
306    format!("Cert check failed for {}: {}", alias, message)
307}
308
309pub fn vault_role_set(role: &str) -> String {
310    format!("Vault SSH role set to {}.", role)
311}
312
313// ── Snippets ────────────────────────────────────────────────────────
314
315pub fn snippet_removed(name: &str) -> String {
316    format!("Removed snippet '{}'.", name)
317}
318
319pub fn snippet_added(name: &str) -> String {
320    format!("Added snippet '{}'.", name)
321}
322
323pub fn snippet_updated(name: &str) -> String {
324    format!("Updated snippet '{}'.", name)
325}
326
327pub fn snippet_exists(name: &str) -> String {
328    format!("'{}' already exists.", name)
329}
330
331pub const OUTPUT_COPIED: &str = "Output copied.";
332
333pub fn copy_failed(e: &impl std::fmt::Display) -> String {
334    format!("Copy failed: {}", e)
335}
336
337// ── Picker (password source, key, proxy) ────────────────────────────
338
339pub const GLOBAL_DEFAULT_CLEARED: &str = "Global default cleared.";
340pub const PASSWORD_SOURCE_CLEARED: &str = "Password source cleared.";
341
342pub fn global_default_set(label: &str) -> String {
343    format!("Global default set to {}.", label)
344}
345
346pub fn password_source_set(label: &str) -> String {
347    format!("Password source set to {}.", label)
348}
349
350pub fn complete_path(label: &str) -> String {
351    format!("Complete the {} path.", label)
352}
353
354pub fn key_selected(name: &str) -> String {
355    format!("Locked and loaded with {}.", name)
356}
357
358pub fn proxy_jump_set(alias: &str) -> String {
359    format!("Jumping through {}.", alias)
360}
361
362pub fn save_default_failed(e: &impl std::fmt::Display) -> String {
363    format!("Failed to save default: {}", e)
364}
365
366// ── Containers ──────────────────────────────────────────────────────
367
368pub fn container_action_complete(action: &str) -> String {
369    format!("Container {} complete.", action)
370}
371
372pub const HOST_KEY_UNKNOWN: &str = "Host key unknown. Connect first (Enter) to trust the host.";
373pub const HOST_KEY_CHANGED: &str =
374    "Host key changed. Possible tampering or server re-install. Clear with ssh-keygen -R.";
375
376// ── Import ──────────────────────────────────────────────────────────
377
378pub fn imported_hosts(imported: usize, skipped: usize) -> String {
379    format!(
380        "Imported {} host{}, skipped {} duplicate{}.",
381        imported,
382        if imported == 1 { "" } else { "s" },
383        skipped,
384        if skipped == 1 { "" } else { "s" }
385    )
386}
387
388pub fn all_hosts_exist(skipped: usize) -> String {
389    if skipped == 1 {
390        "Host already exists.".to_string()
391    } else {
392        format!("All {} hosts already exist.", skipped)
393    }
394}
395
396// ── SSH config repair ───────────────────────────────────────────────
397
398pub fn config_repaired(groups: usize, orphaned: usize) -> String {
399    format!(
400        "Repaired SSH config ({} absorbed, {} orphaned group headers).",
401        groups, orphaned
402    )
403}
404
405pub fn no_exact_match(alias: &str) -> String {
406    format!("No exact match for '{}'. Here's what we found.", alias)
407}
408
409pub fn group_pref_reset_failed(e: &impl std::fmt::Display) -> String {
410    format!("Group preference reset. (save failed: {})", e)
411}
412
413// ── Connection ──────────────────────────────────────────────────────
414
415pub fn opened_in_tmux(alias: &str) -> String {
416    format!("Opened {} in new tmux window.", alias)
417}
418
419pub fn tmux_error(e: &impl std::fmt::Display) -> String {
420    format!("tmux: {}", e)
421}
422
423pub fn connection_failed(alias: &str) -> String {
424    format!("Connection to {} failed.", alias)
425}
426
427// ── Host key reset ──────────────────────────────────────────────────
428
429pub fn host_key_remove_failed(stderr: &str) -> String {
430    format!("Failed to remove host key: {}", stderr)
431}
432
433pub fn ssh_keygen_failed(e: &impl std::fmt::Display) -> String {
434    format!("Failed to run ssh-keygen: {}", e)
435}
436
437// ── Transfer ────────────────────────────────────────────────────────
438
439pub const TRANSFER_COMPLETE: &str = "Transfer complete.";
440
441// ── Background / event loop ─────────────────────────────────────────
442
443pub const PING_EXPIRED: &str = "Ping expired. Press P to refresh.";
444
445/// Per-provider sync progress line with a leading spinner frame so
446/// `event_loop::handle_tick` animates the prefix while the message is
447/// on screen. Format: `⠋ Proxmox VE: Resolving IPs (1/5)...`. Mirrors
448/// the spinner contract used by `synced_progress` so the footer keeps
449/// animating even when granular per-provider progress overrides the
450/// batch summary mid-sync.
451pub fn provider_progress(spinner: &str, name: &str, message: &str) -> String {
452    format!("{} {}: {}", spinner, name, message)
453}
454
455// ── Vault SSH bulk signing summaries (event_loop.rs) ────────────────
456
457pub fn vault_config_reapply_failed(signed: usize, e: &impl std::fmt::Display) -> String {
458    format!(
459        "External edits detected; signed {} certs but failed to re-apply CertificateFile: {}",
460        signed, e
461    )
462}
463
464pub fn vault_external_edits_merged(summary: &str, reapplied: usize) -> String {
465    format!(
466        "{} External ssh config edits detected, merged {} CertificateFile directives.",
467        summary, reapplied
468    )
469}
470
471pub fn vault_external_edits_no_write(summary: &str) -> String {
472    format!(
473        "{} External ssh config edits detected; certs on disk, no CertificateFile written.",
474        summary
475    )
476}
477
478pub fn vault_reparse_failed(signed: usize, e: &impl std::fmt::Display) -> String {
479    format!(
480        "Signed {} certs but cannot re-parse ssh config after external edit: {}. \
481         Certs are on disk under ~/.purple/certs/.",
482        signed, e
483    )
484}
485
486pub fn vault_config_update_failed(signed: usize, e: &impl std::fmt::Display) -> String {
487    format!(
488        "Signed {} certs but failed to update SSH config: {}",
489        signed, e
490    )
491}
492
493pub fn vault_config_write_after_sign(e: &impl std::fmt::Display) -> String {
494    format!("Failed to update config after vault signing: {}", e)
495}
496
497// ── File browser ────────────────────────────────────────────────────
498
499// ── Confirm / host key ──────────────────────────────────────────────
500
501pub fn removed_host_key(hostname: &str) -> String {
502    format!("Removed host key for {}. Reconnecting...", hostname)
503}
504
505// ── Host detail (tags) ──────────────────────────────────────────────
506
507pub fn tagged_host(alias: &str, count: usize) -> String {
508    format!(
509        "Tagged {} with {} label{}.",
510        alias,
511        count,
512        if count == 1 { "" } else { "s" }
513    )
514}
515
516// ── Config reload ───────────────────────────────────────────────────
517
518pub fn config_reloaded(count: usize) -> String {
519    format!("Config reloaded. {} hosts.", count)
520}
521
522// ── Sync background ─────────────────────────────────────────────────
523
524/// In-progress sync line for the footer. Format:
525/// `⠋ Syncing AWS, Hetzner · 1/3 (+12 ~3 -1)`.
526/// Active provider names lead so the user immediately sees which provider
527/// is currently in flight (especially relevant when one provider is slow).
528/// `done/total` follows as a counter. The leading character is a braille
529/// spinner frame rotated on every tick. The `(+a ~u -s)` suffix is omitted
530/// when all counts are zero.
531///
532/// Callers MUST only invoke this when `active_names` is non-empty (i.e.
533/// at least one provider is still in flight). The only call site is
534/// `main::set_sync_summary`, which enters this branch via `still_syncing`,
535/// itself gated on `!providers.syncing.is_empty()` — so `active_names`
536/// (built from `syncing.keys()`) is guaranteed non-empty.
537pub fn synced_progress(
538    spinner: &str,
539    active_names: &str,
540    done: usize,
541    total: usize,
542    added: usize,
543    updated: usize,
544    stale: usize,
545) -> String {
546    debug_assert!(
547        !active_names.is_empty(),
548        "synced_progress must only be called while a provider is still in flight"
549    );
550    let diff = sync_diff_suffix(added, updated, stale);
551    format!(
552        "{} Syncing {} \u{00B7} {}/{}{}",
553        spinner, active_names, done, total, diff
554    )
555}
556
557/// Final sync summary for the footer once all providers in the batch have
558/// completed. Format: `Synced 5/5 · AWS, DO, Vultr, Hetzner, Linode (+12 ~3 -1)`.
559/// No spinner prefix, no auto-tick: the message expires by length-proportional
560/// timeout once the batch is done.
561pub fn synced_done(
562    done: usize,
563    total: usize,
564    names: &str,
565    added: usize,
566    updated: usize,
567    stale: usize,
568) -> String {
569    let diff = sync_diff_suffix(added, updated, stale);
570    format!("Synced {}/{} \u{00B7} {}{}", done, total, names, diff)
571}
572
573fn sync_diff_suffix(added: usize, updated: usize, stale: usize) -> String {
574    let parts: Vec<String> = [(added, '+'), (updated, '~'), (stale, '-')]
575        .iter()
576        .filter(|(n, _)| *n > 0)
577        .map(|(n, sign)| format!("{}{}", sign, n))
578        .collect();
579    if parts.is_empty() {
580        String::new()
581    } else {
582        format!(" ({})", parts.join(" "))
583    }
584}
585
586pub const SYNC_THREAD_SPAWN_FAILED: &str = "Failed to start sync thread.";
587
588pub const SYNC_UNKNOWN_PROVIDER: &str = "Unknown provider.";
589
590// ── Vault signing cancelled summary ─────────────────────────────────
591
592pub fn vault_signing_cancelled_summary(
593    signed: u32,
594    failed: u32,
595    first_error: Option<&str>,
596) -> String {
597    let mut msg = format!(
598        "Vault SSH signing cancelled ({} signed, {} failed)",
599        signed, failed
600    );
601    if let Some(err) = first_error {
602        msg.push_str(": ");
603        msg.push_str(err);
604    }
605    msg
606}
607
608// ── Region picker ───────────────────────────────────────────────────
609
610pub fn regions_selected_count(count: usize, label: &str) -> String {
611    let s = if count == 1 { "" } else { "s" };
612    format!("{} {}{} selected.", count, label, s)
613}
614
615// ── Purge stale ─────────────────────────────────────────────────────
616
617// ── Clipboard ───────────────────────────────────────────────────────
618
619pub const NO_CLIPBOARD_TOOL: &str =
620    "No clipboard tool found. Install pbcopy (macOS), wl-copy (Wayland), or xclip/xsel (X11).";
621
622// ── CLI messages ────────────────────────────────────────────────────
623
624#[path = "messages/cli.rs"]
625pub mod cli;
626
627// ── Update messages ─────────────────────────────────────────────────
628
629pub mod update {
630    pub const WHATS_NEW_HINT: &str = "Press n inside purple to see what's new.";
631    pub const DONE: &str = "done.";
632    pub const CHECKSUM_OK: &str = "ok.";
633    pub const SUDO_WARNING: &str =
634        "Running via sudo. Consider fixing directory permissions instead.";
635
636    pub fn already_on(current: &str) -> String {
637        format!("already on v{} (latest).", current)
638    }
639
640    pub fn available(latest: &str, current: &str) -> String {
641        format!("v{} available (current: v{}).", latest, current)
642    }
643
644    pub fn header(bold_name: &str) -> String {
645        format!("\n  {} updater\n", bold_name)
646    }
647
648    pub fn binary_path(path: &std::path::Path) -> String {
649        format!("  Binary: {}", path.display())
650    }
651
652    pub fn installed_at(bold_version: &str, path: &std::path::Path) -> String {
653        format!("\n  {} installed at {}.", bold_version, path.display())
654    }
655
656    pub fn whats_new_hint_indented() -> String {
657        format!("\n  {}", WHATS_NEW_HINT)
658    }
659}
660
661// ── Askpass / password prompts ───────────────────────────────────────
662
663pub mod askpass {
664    pub const BW_NOT_FOUND: &str = "Bitwarden CLI (bw) not found. SSH will prompt for password.";
665    pub const BW_NOT_LOGGED_IN: &str = "Bitwarden vault not logged in. Run 'bw login' first.";
666    pub const EMPTY_PASSWORD: &str = "Empty password. SSH will prompt for password.";
667    pub const PASSWORD_IN_KEYCHAIN: &str = "Password stored in keychain.";
668
669    pub fn read_failed(e: &impl std::fmt::Display) -> String {
670        format!("Failed to read password: {}", e)
671    }
672
673    pub fn unlock_failed_retry(e: &impl std::fmt::Display) -> String {
674        format!("Unlock failed: {}. Try again.", e)
675    }
676
677    pub fn unlock_failed_prompt(e: &impl std::fmt::Display) -> String {
678        format!("Unlock failed: {}. SSH will prompt for password.", e)
679    }
680}
681
682// ── Logging ─────────────────────────────────────────────────────────
683
684pub mod logging {
685    pub fn init_failed(e: &impl std::fmt::Display) -> String {
686        format!("[purple] Failed to initialize logger: {}", e)
687    }
688
689    pub const SSH_VERSION_FAILED: &str = "[purple] Failed to detect SSH version. Is ssh installed?";
690}
691
692// ── Form field hints / placeholders ─────────────────────────────────
693//
694// Dimmed placeholder text shown in empty form fields. Centralized here
695// so every user-visible string lives in one place and is auditable.
696
697pub mod hints {
698    // ── Shared ──────────────────────────────────────────────────────
699    // Picker hints mention "Space" because per the design system keyboard
700    // invariants, Enter always submits a form; pickers open on Space.
701    // Keep these strings in sync with scripts/check-keybindings.sh.
702    pub const IDENTITY_FILE_PICK: &str = "Space to pick a key";
703    pub const DEFAULT_SSH_USER: &str = "root";
704
705    // ── Host form ───────────────────────────────────────────────────
706    pub const HOST_ALIAS: &str = "e.g. prod or db-01";
707    pub const HOST_ALIAS_PATTERN: &str = "10.0.0.* or *.example.com";
708    pub const HOST_HOSTNAME: &str = "192.168.1.1 or example.com";
709    pub const HOST_PORT: &str = "22";
710    pub const HOST_PROXY_JUMP: &str = "Space to pick a host";
711    pub const HOST_VAULT_SSH: &str = "e.g. ssh-client-signer/sign/my-role (auth via vault login)";
712    pub const HOST_VAULT_SSH_PICKER: &str = "Space to pick a role or type one";
713    pub const HOST_VAULT_ADDR: &str =
714        "e.g. http://127.0.0.1:8200 (inherits from provider or env when empty)";
715    pub const HOST_TAGS: &str = "e.g. prod, staging, us-east (comma-separated)";
716    pub const HOST_ASKPASS_PICK: &str = "Space to pick a source";
717
718    pub fn askpass_default(default: &str) -> String {
719        format!("default: {}", default)
720    }
721
722    pub fn inherits_from(value: &str, provider: &str) -> String {
723        format!("inherits {} from {}", value, provider)
724    }
725
726    // ── Tunnel form ─────────────────────────────────────────────────
727    pub const TUNNEL_BIND_PORT: &str = "8080";
728    pub const TUNNEL_REMOTE_HOST: &str = "localhost";
729    pub const TUNNEL_REMOTE_PORT: &str = "80";
730
731    // ── Snippet form ────────────────────────────────────────────────
732    pub const SNIPPET_NAME: &str = "check-disk";
733    pub const SNIPPET_COMMAND: &str = "df -h";
734    pub const SNIPPET_OPTIONAL: &str = "(optional)";
735
736    // ── Provider form ───────────────────────────────────────────────
737    pub const PROVIDER_URL: &str = "https://pve.example.com:8006";
738    pub const PROVIDER_TOKEN_DEFAULT: &str = "your-api-token";
739    pub const PROVIDER_TOKEN_PROXMOX: &str = "user@pam!token=secret";
740    pub const PROVIDER_TOKEN_AWS: &str = "AccessKeyId:Secret (or use Profile)";
741    pub const PROVIDER_TOKEN_GCP: &str = "/path/to/service-account.json (or access token)";
742    pub const PROVIDER_TOKEN_AZURE: &str = "/path/to/service-principal.json (or access token)";
743    pub const PROVIDER_TOKEN_TAILSCALE: &str = "API key (leave empty for local CLI)";
744    pub const PROVIDER_TOKEN_ORACLE: &str = "~/.oci/config";
745    pub const PROVIDER_TOKEN_OVH: &str = "app_key:app_secret:consumer_key";
746    pub const PROVIDER_PROFILE: &str = "Name from ~/.aws/credentials (or use Token)";
747    pub const PROVIDER_PROJECT_DEFAULT: &str = "my-gcp-project-id";
748    pub const PROVIDER_PROJECT_OVH: &str = "Public Cloud project ID";
749    pub const PROVIDER_COMPARTMENT: &str = "ocid1.compartment.oc1..aaaa...";
750    pub const PROVIDER_REGIONS_DEFAULT: &str = "Space to select regions";
751    pub const PROVIDER_REGIONS_GCP: &str = "Space to select zones (empty = all)";
752    pub const PROVIDER_REGIONS_SCALEWAY: &str = "Space to select zones";
753    // Azure regions is a text input (not a picker), so no key is mentioned.
754    pub const PROVIDER_REGIONS_AZURE: &str = "comma-separated subscription IDs";
755    pub const PROVIDER_REGIONS_OVH: &str = "Space to select endpoint (default: EU)";
756    pub const PROVIDER_USER_AWS: &str = "ec2-user";
757    pub const PROVIDER_USER_GCP: &str = "ubuntu";
758    pub const PROVIDER_USER_AZURE: &str = "azureuser";
759    pub const PROVIDER_USER_ORACLE: &str = "opc";
760    pub const PROVIDER_USER_OVH: &str = "ubuntu";
761    pub const PROVIDER_VAULT_ROLE: &str =
762        "e.g. ssh-client-signer/sign/my-role (vault login; inherited)";
763    pub const PROVIDER_VAULT_ADDR: &str = "e.g. http://127.0.0.1:8200 (inherited by all hosts)";
764    pub const PROVIDER_ALIAS_PREFIX_DEFAULT: &str = "prefix";
765}
766
767#[cfg(test)]
768mod hints_tests {
769    use super::hints;
770
771    #[test]
772    fn askpass_default_formats() {
773        assert_eq!(hints::askpass_default("keychain"), "default: keychain");
774    }
775
776    #[test]
777    fn askpass_default_formats_empty() {
778        assert_eq!(hints::askpass_default(""), "default: ");
779    }
780
781    #[test]
782    fn inherits_from_formats() {
783        assert_eq!(
784            hints::inherits_from("role/x", "aws"),
785            "inherits role/x from aws"
786        );
787    }
788
789    #[test]
790    fn picker_hints_mention_space_not_enter() {
791        // Per the keyboard invariants, pickers open on Space.
792        // If these assertions fail, audit scripts/check-keybindings.sh too.
793        for s in [
794            hints::IDENTITY_FILE_PICK,
795            hints::HOST_PROXY_JUMP,
796            hints::HOST_VAULT_SSH_PICKER,
797            hints::HOST_ASKPASS_PICK,
798            hints::PROVIDER_REGIONS_DEFAULT,
799            hints::PROVIDER_REGIONS_GCP,
800            hints::PROVIDER_REGIONS_SCALEWAY,
801            hints::PROVIDER_REGIONS_OVH,
802        ] {
803            assert!(
804                s.starts_with("Space "),
805                "picker hint must mention Space: {s}"
806            );
807            assert!(!s.contains("Enter "), "picker hint must not say Enter: {s}");
808        }
809    }
810}
811
812#[path = "messages/whats_new.rs"]
813pub mod whats_new;
814
815#[path = "messages/whats_new_toast.rs"]
816pub mod whats_new_toast;