1pub mod container;
13pub mod host;
14pub mod picker;
15pub mod provider;
16pub mod snippet;
17pub mod tunnel;
18pub mod vault;
19
20pub use container::*;
21pub use host::*;
22pub use picker::*;
23pub use provider::*;
24pub use snippet::*;
25pub use tunnel::*;
26pub use vault::*;
27
28pub const FAILED_TO_SAVE: &str = "Failed to save";
31pub fn failed_to_save(e: &impl std::fmt::Display) -> String {
32 format!("{}: {}", FAILED_TO_SAVE, e)
33}
34
35pub const CONFIG_CHANGED_EXTERNALLY: &str =
36 "Config changed externally. Press Esc and re-open to pick up changes.";
37
38pub const WELCOME_BACKUP_TAKEN: &str = "Your original config has been backed up";
41pub fn welcome_backup_location(path: &str) -> String {
43 format!("to {path}")
44}
45
46pub const DEMO_CONNECTION_DISABLED: &str = "Demo mode. Connection disabled.";
49pub const DEMO_SYNC_DISABLED: &str = "Demo mode. Sync disabled.";
50pub const DEMO_TUNNELS_DISABLED: &str = "Demo mode. Tunnels disabled.";
51pub const DEMO_VAULT_SIGNING_DISABLED: &str = "Demo mode. Vault SSH signing disabled.";
52pub const DEMO_FILE_BROWSER_DISABLED: &str = "Demo mode. File browser disabled.";
53pub const DEMO_CONTAINER_REFRESH_DISABLED: &str = "Demo mode. Container refresh disabled.";
54pub const DEMO_CONTAINER_ACTIONS_DISABLED: &str = "Demo mode. Container actions disabled.";
55pub const DEMO_EXECUTION_DISABLED: &str = "Demo mode. Execution disabled.";
56pub const DEMO_PROVIDER_CHANGES_DISABLED: &str = "Demo mode. Provider config changes disabled.";
57
58pub fn pinging_host(alias: &str, show_hint: bool) -> String {
61 if show_hint {
62 format!("Pinging {}... (Shift+P pings all)", alias)
63 } else {
64 format!("Pinging {}...", alias)
65 }
66}
67
68pub fn bastion_not_found(alias: &str) -> String {
69 format!("Bastion {} not found in config.", alias)
70}
71
72pub fn ping_skipped_proxied(alias: &str) -> String {
73 format!("{} connects through a ProxyCommand. Ping skipped.", alias)
74}
75
76pub fn clipboard_run_failed(cmd: &str) -> String {
82 format!("Failed to run {}.", cmd)
83}
84
85pub fn clipboard_write_failed(cmd: &str) -> String {
86 format!("Failed to write to {}.", cmd)
87}
88
89pub fn clipboard_wait_failed(cmd: &str) -> String {
90 format!("Failed to wait for {}.", cmd)
91}
92
93pub fn clipboard_exited_error(cmd: &str) -> String {
94 format!("{} exited with error.", cmd)
95}
96
97pub fn import_open_failed(path: &impl std::fmt::Display, e: &impl std::fmt::Display) -> String {
103 format!("Can't open {}: {}", path, e)
104}
105
106pub fn import_known_hosts_open_failed(e: &impl std::fmt::Display) -> String {
107 format!("Can't open known_hosts: {}", e)
108}
109
110pub const IMPORT_HOME_DIR_UNKNOWN: &str = "Could not determine home directory.";
111pub const IMPORT_KNOWN_HOSTS_MISSING: &str = "~/.ssh/known_hosts not found.";
112
113pub fn imported_hosts(imported: usize, skipped: usize) -> String {
116 format!(
117 "Imported {} host{}, skipped {} duplicate{}.",
118 imported,
119 if imported == 1 { "" } else { "s" },
120 skipped,
121 if skipped == 1 { "" } else { "s" }
122 )
123}
124
125pub fn all_hosts_exist(skipped: usize) -> String {
126 if skipped == 1 {
127 "Host already exists.".to_string()
128 } else {
129 format!("All {} hosts already exist.", skipped)
130 }
131}
132
133pub fn opened_in_tmux(alias: &str) -> String {
136 format!("Opened {} in new tmux window.", alias)
137}
138
139pub fn tmux_error(e: &impl std::fmt::Display) -> String {
140 format!("tmux: {}", e)
141}
142
143pub fn connection_failed(alias: &str) -> String {
144 format!("Connection to {} failed.", alias)
145}
146
147pub fn connection_spawn_failed(e: &impl std::fmt::Display) -> String {
151 format!("Connection failed: {}", e)
152}
153
154pub fn ssh_failed_with_reason(alias: &str, reason: &str) -> String {
157 format!("SSH to {} failed. {}", alias, reason)
158}
159
160pub fn ssh_exited_with_code(alias: &str, code: i32) -> String {
163 format!("SSH to {} exited with code {}.", alias, code)
164}
165
166pub const TRANSFER_COMPLETE: &str = "Transfer complete.";
169
170pub fn provider_progress(spinner: &str, name: &str, message: &str) -> String {
179 format!("{} {}: {}", spinner, name, message)
180}
181
182pub const AGE_JUST_NOW: &str = "just now";
185
186pub fn relative_age(elapsed: std::time::Duration) -> String {
190 let secs = elapsed.as_secs();
191 if secs < 5 {
192 AGE_JUST_NOW.to_string()
193 } else if secs < 60 {
194 format!("{}s ago", secs)
195 } else if secs < 3600 {
196 format!("{}m ago", secs / 60)
197 } else if secs < 86400 {
198 format!("{}h ago", secs / 3600)
199 } else {
200 format!("{}d ago", secs / 86400)
201 }
202}
203
204pub fn config_reloaded(count: usize) -> String {
207 format!("Config reloaded. {} hosts.", count)
208}
209
210pub fn synced_progress(
226 spinner: &str,
227 active_names: &str,
228 done: usize,
229 total: usize,
230 added: usize,
231 updated: usize,
232 stale: usize,
233) -> String {
234 debug_assert!(
235 !active_names.is_empty(),
236 "synced_progress must only be called while a provider is still in flight"
237 );
238 let diff = sync_diff_suffix(added, updated, stale);
239 format!(
240 "{} Syncing {} \u{00B7} {}/{}{}",
241 spinner, active_names, done, total, diff
242 )
243}
244
245pub fn synced_done(
250 done: usize,
251 total: usize,
252 names: &str,
253 added: usize,
254 updated: usize,
255 stale: usize,
256) -> String {
257 let diff = sync_diff_suffix(added, updated, stale);
258 format!("Synced {}/{} \u{00B7} {}{}", done, total, names, diff)
259}
260
261fn sync_diff_suffix(added: usize, updated: usize, stale: usize) -> String {
262 let parts: Vec<String> = [(added, '+'), (updated, '~'), (stale, '-')]
263 .iter()
264 .filter(|(n, _)| *n > 0)
265 .map(|(n, sign)| format!("{}{}", sign, n))
266 .collect();
267 if parts.is_empty() {
268 String::new()
269 } else {
270 format!(" ({})", parts.join(" "))
271 }
272}
273
274pub const SYNC_THREAD_SPAWN_FAILED: &str = "Failed to start sync thread.";
275
276pub const SYNC_UNKNOWN_PROVIDER: &str = "Unknown provider.";
277
278pub fn sync_skipped_external_change() -> &'static str {
279 "Config changed on disk during sync. Re-run sync after reviewing your edits."
280}
281
282pub const NO_CLIPBOARD_TOOL: &str =
285 "No clipboard tool found. Install pbcopy (macOS), wl-copy (Wayland), or xclip/xsel (X11).";
286
287pub const MCP_TOOL_DENIED_READ_ONLY: &str = "Tool denied. Server started with --read-only. Restart without --read-only to enable state-changing tools.";
290
291pub fn mcp_audit_init_failed(path: &impl std::fmt::Display, e: &impl std::fmt::Display) -> String {
295 format!(
296 "Failed to initialise MCP audit log at {}: {}. Continuing without audit logging.",
297 path, e
298 )
299}
300
301pub fn mcp_audit_write_failed(e: &impl std::fmt::Display) -> String {
303 format!("Failed to write MCP audit entry: {}", e)
304}
305
306pub fn mcp_config_file_not_found(path: &impl std::fmt::Display) -> String {
310 format!("SSH config file not found: {}", path)
311}
312
313pub const MCP_AUDIT_HOME_DIR_UNAVAILABLE: &str = "Could not determine home directory; MCP audit log disabled. Set --audit-log <PATH> explicitly to enable auditing.";
317
318pub const PALETTE_PLACEHOLDER: &str = "Find anything";
322pub const PALETTE_NO_RESULTS: &str = "No matches.";
324pub const PALETTE_SNIPPET_NEEDS_HOST: &str =
327 "Pick a host first, then run a snippet from the jump bar.";
328pub fn jump_more_rows(n: usize) -> String {
331 format!("+{n} more (scroll down)")
332}
333
334#[path = "messages/cli.rs"]
337pub mod cli;
338pub mod footer;
339
340pub mod update {
343 pub const WHATS_NEW_HINT: &str = "Press n inside purple to see what's new.";
344 pub const DONE: &str = "done.";
345 pub const CHECKSUM_OK: &str = "ok.";
346 pub const SUDO_WARNING: &str =
347 "Running via sudo. Consider fixing directory permissions instead.";
348
349 pub const STEP_CHECKING: &str = " Checking for updates... ";
354 pub const STEP_VERIFYING_CHECKSUM: &str = " Verifying checksum... ";
355 pub const STEP_INSTALLING: &str = " Installing... ";
356
357 pub fn already_on(current: &str) -> String {
358 format!("already on v{} (latest).", current)
359 }
360
361 pub fn available(latest: &str, current: &str) -> String {
362 format!("v{} available (current: v{}).", latest, current)
363 }
364
365 pub fn step_downloading(version: &str) -> String {
369 format!(" Downloading v{}... ", version)
370 }
371
372 pub fn sudo_warning_line(bold_bang: &str) -> String {
376 format!(" {} {}", bold_bang, SUDO_WARNING)
377 }
378
379 pub fn header(bold_name: &str) -> String {
380 format!("\n {} updater\n", bold_name)
381 }
382
383 pub fn binary_path(path: &std::path::Path) -> String {
384 format!(" Binary: {}", path.display())
385 }
386
387 pub fn installed_at(bold_version: &str, path: &std::path::Path) -> String {
388 format!("\n {} installed at {}.", bold_version, path.display())
389 }
390
391 pub fn whats_new_hint_indented() -> String {
392 format!("\n {}", WHATS_NEW_HINT)
393 }
394}
395
396pub mod askpass {
399 pub const BW_NOT_FOUND: &str = "Bitwarden CLI (bw) not found. SSH will prompt for password.";
400 pub const BW_NOT_LOGGED_IN: &str = "Bitwarden vault not logged in. Run 'bw login' first.";
401 pub const EMPTY_PASSWORD: &str = "Empty password. SSH will prompt for password.";
402 pub const PASSWORD_IN_KEYCHAIN: &str = "Password stored in keychain.";
403
404 pub fn read_failed(e: &impl std::fmt::Display) -> String {
405 format!("Failed to read password: {}", e)
406 }
407
408 pub fn unlock_failed_retry(e: &impl std::fmt::Display) -> String {
409 format!("Unlock failed: {}. Try again.", e)
410 }
411
412 pub fn unlock_failed_prompt(e: &impl std::fmt::Display) -> String {
413 format!("Unlock failed: {}. SSH will prompt for password.", e)
414 }
415
416 pub fn password_prompt(alias: &str) -> String {
420 format!("Password for {}: ", alias)
421 }
422
423 pub fn keychain_password_prompt(alias: &str) -> String {
426 format!("Password for {} (stored in keychain): ", alias)
427 }
428
429 pub fn keychain_store_failed(e: &impl std::fmt::Display) -> String {
432 format!(
433 "Failed to store in keychain: {}. SSH will prompt for password.",
434 e
435 )
436 }
437
438 pub const PROTON_NOT_FOUND: &str =
439 "Proton Pass CLI (pass-cli) not found. SSH will prompt for password.";
440
441 pub const PROTON_LOGIN_PROMPT: &str = "Proton Pass PAT: ";
442
443 pub const PROTON_LOGIN_SUCCESS: &str = "Logged in to Proton Pass.";
444
445 pub fn proton_login_failed_retry(e: &impl std::fmt::Display) -> String {
446 format!("Proton Pass login failed: {}. Try again.", e)
447 }
448
449 pub fn proton_login_failed_prompt(e: &impl std::fmt::Display) -> String {
450 format!(
451 "Proton Pass login failed: {}. SSH will prompt for password.",
452 e
453 )
454 }
455}
456
457pub mod logging {
460 pub fn init_failed(e: &impl std::fmt::Display) -> String {
461 format!("[purple] Failed to initialize logger: {}", e)
462 }
463
464 pub const SSH_VERSION_FAILED: &str = "[purple] Failed to detect SSH version. Is ssh installed?";
465}
466
467pub mod hints {
473 pub const IDENTITY_FILE_PICK: &str = "Space to pick a key";
478 pub const DEFAULT_SSH_USER: &str = "root";
479
480 pub const HOST_ALIAS: &str = "e.g. prod or db-01";
482 pub const HOST_ALIAS_PATTERN: &str = "10.0.0.* or *.example.com";
483 pub const HOST_HOSTNAME: &str = "192.168.1.1 or example.com";
484 pub const HOST_PORT: &str = "22";
485 pub const HOST_PROXY_JUMP: &str = "Space to pick a host";
486 pub const HOST_VAULT_SSH: &str = "e.g. ssh-client-signer/sign/my-role (auth via vault login)";
487 pub const HOST_VAULT_SSH_PICKER: &str = "Space to pick a role or type one";
488 pub const HOST_VAULT_ADDR: &str =
489 "e.g. http://127.0.0.1:8200 (inherits from provider or env when empty)";
490 pub const HOST_TAGS: &str = "e.g. prod, staging, us-east (comma-separated)";
491 pub const HOST_ASKPASS_PICK: &str = "Space to pick a source";
492
493 pub fn askpass_default(default: &str) -> String {
494 format!("default: {}", default)
495 }
496
497 pub fn inherits_from(value: &str, provider: &str) -> String {
498 format!("inherits {} from {}", value, provider)
499 }
500
501 pub const TUNNEL_BIND_PORT: &str = "8080";
503 pub const TUNNEL_REMOTE_HOST: &str = "localhost";
504 pub const TUNNEL_REMOTE_PORT: &str = "80";
505
506 pub const SNIPPET_NAME: &str = "check-disk";
508 pub const SNIPPET_COMMAND: &str = "df -h";
509 pub const SNIPPET_OPTIONAL: &str = "(optional)";
510 pub const SNIPPET_DEFAULT_HOSTS: &str = "Space to pick hosts";
512
513 pub const PROVIDER_URL: &str = "https://pve.example.com:8006";
515 pub const PROVIDER_URL_NETBOX: &str = "https://netbox.example.com";
516 pub const PROVIDER_TOKEN_DEFAULT: &str = "your-api-token";
517 pub const PROVIDER_TOKEN_PROXMOX: &str = "user@pam!token=secret";
518 pub const PROVIDER_TOKEN_NETBOX: &str = "nbt_... (v2) or classic API token";
519 pub const PROVIDER_TOKEN_AWS: &str = "AccessKeyId:Secret[:SessionToken] (or Profile or env)";
520 pub const PROVIDER_TOKEN_GCP: &str = "/path/to/service-account.json (or access token)";
521 pub const PROVIDER_TOKEN_AZURE: &str = "/path/to/service-principal.json (or access token)";
522 pub const PROVIDER_TOKEN_TAILSCALE: &str = "API key (leave empty for local CLI)";
523 pub const PROVIDER_TOKEN_TELEPORT: &str = "not used (tsh login holds the session)";
524 pub const PROVIDER_TOKEN_ORACLE: &str = "~/.oci/config";
525 pub const PROVIDER_TOKEN_OVH: &str = "app_key:app_secret:consumer_key";
526 pub const PROVIDER_PROFILE: &str = "Space to select a profile (or use Token)";
527 pub const PROVIDER_PROJECT_DEFAULT: &str = "my-gcp-project-id";
528 pub const PROVIDER_PROJECT_OVH: &str = "Public Cloud project ID";
529 pub const PROVIDER_COMPARTMENT: &str = "ocid1.compartment.oc1..aaaa...";
530 pub const PROVIDER_REGIONS_DEFAULT: &str = "Space to select regions";
531 pub const PROVIDER_REGIONS_GCP: &str = "Space to select zones (empty = all)";
532 pub const PROVIDER_REGIONS_SCALEWAY: &str = "Space to select zones";
533 pub const PROVIDER_REGIONS_AZURE: &str = "comma-separated subscription IDs";
535 pub const PROVIDER_REGIONS_OVH: &str = "Space to select endpoint (default: EU)";
536 pub const PROVIDER_FILTER_NETBOX: &str = "status=active&tag=ssh (NetBox query params)";
537
538 pub fn ssm_mode_value(mode: crate::providers::aws_ssm::SsmMode) -> &'static str {
541 use crate::providers::aws_ssm::SsmMode;
542 match mode {
543 SsmMode::Off => "off (connect to the IP address)",
544 SsmMode::Auto => "auto (route the nodes SSM reports online)",
545 SsmMode::Always => "always (route every instance)",
546 }
547 }
548 pub const PROVIDER_USER_AWS: &str = "ec2-user";
549 pub const PROVIDER_USER_GCP: &str = "ubuntu";
550 pub const PROVIDER_USER_AZURE: &str = "azureuser";
551 pub const PROVIDER_USER_ORACLE: &str = "opc";
552 pub const PROVIDER_USER_OVH: &str = "ubuntu";
553 pub const PROVIDER_USER_TELEPORT: &str = "Teleport login, e.g. root (empty = local user)";
554 pub const PROVIDER_VAULT_ROLE: &str =
555 "e.g. ssh-client-signer/sign/my-role (vault login; inherited)";
556 pub const PROVIDER_VAULT_ADDR: &str = "e.g. http://127.0.0.1:8200 (inherited by all hosts)";
557 pub const PROVIDER_ALIAS_PREFIX_DEFAULT: &str = "prefix";
558 pub const PROVIDER_LABEL: &str = "short name, e.g. server1 or work";
559}
560
561#[cfg(test)]
562mod hints_tests {
563 use super::hints;
564
565 #[test]
566 fn askpass_default_formats() {
567 assert_eq!(hints::askpass_default("keychain"), "default: keychain");
568 }
569
570 #[test]
571 fn askpass_default_formats_empty() {
572 assert_eq!(hints::askpass_default(""), "default: ");
573 }
574
575 #[test]
576 fn inherits_from_formats() {
577 assert_eq!(
578 hints::inherits_from("role/x", "aws"),
579 "inherits role/x from aws"
580 );
581 }
582
583 #[test]
584 fn picker_hints_mention_space_not_enter() {
585 for s in [
588 hints::IDENTITY_FILE_PICK,
589 hints::HOST_PROXY_JUMP,
590 hints::HOST_VAULT_SSH_PICKER,
591 hints::HOST_ASKPASS_PICK,
592 hints::PROVIDER_REGIONS_DEFAULT,
593 hints::PROVIDER_REGIONS_GCP,
594 hints::PROVIDER_REGIONS_SCALEWAY,
595 hints::PROVIDER_REGIONS_OVH,
596 hints::PROVIDER_PROFILE,
597 ] {
598 assert!(
599 s.starts_with("Space "),
600 "picker hint must mention Space: {s}"
601 );
602 assert!(!s.contains("Enter "), "picker hint must not say Enter: {s}");
603 }
604 }
605}
606
607#[path = "messages/whats_new.rs"]
608pub mod whats_new;
609
610#[path = "messages/whats_new_toast.rs"]
611pub mod whats_new_toast;
612
613#[cfg(test)]
614mod relative_age_tests {
615 use super::relative_age;
616 use std::time::Duration;
617
618 #[test]
619 fn relative_age_boundaries() {
620 assert_eq!(relative_age(Duration::from_secs(0)), "just now");
621 assert_eq!(relative_age(Duration::from_secs(4)), "just now");
622 assert_eq!(relative_age(Duration::from_secs(5)), "5s ago");
623 assert_eq!(relative_age(Duration::from_secs(59)), "59s ago");
624 assert_eq!(relative_age(Duration::from_secs(60)), "1m ago");
625 assert_eq!(relative_age(Duration::from_secs(3599)), "59m ago");
626 assert_eq!(relative_age(Duration::from_secs(3600)), "1h ago");
627 assert_eq!(relative_age(Duration::from_secs(86399)), "23h ago");
628 assert_eq!(relative_age(Duration::from_secs(86400)), "1d ago");
629 assert_eq!(relative_age(Duration::from_secs(86400 * 7)), "7d ago");
630 }
631}