susshi 0.13.2

A modern terminal-based SSH connection manager with a beautiful Catppuccin TUI
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
//! Internationalisation (i18n) — textes de l'interface TUI.
//!
//! Deux langues supportées : Français (`Fr`) et Anglais (`En`).
//! La langue est détectée une seule fois au démarrage via les variables
//! d'environnement `LC_ALL` → `LC_MESSAGES` → `LANG`.
//!
//! ## Gabarits de format
//!
//! Les champs dont la valeur contient `{}` sont des gabarits substituables.
//! Utiliser [`fmt`] ou [`str::replacen`] pour les instancier.

// ─── Types ────────────────────────────────────────────────────────────────────

/// Langue de l'interface.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Lang {
    Fr,
    En,
}

/// Ensemble des textes de l'interface TUI.
///
/// Les champs contenant `{}` sont des gabarits à instancier via [`fmt`].
pub struct Strings {
    // ── Fenêtre erreur ──────────────────────────────────────────────────────
    pub error_title: &'static str,
    pub error_dismiss: &'static str,

    // ── Onglets connexion ───────────────────────────────────────────────────
    pub tab_title: &'static str,
    /// Libellé de l'onglet Direct (affiché dans le widget Tabs et pour la détection clic).
    pub tab_direct: &'static str,
    /// Libellé de l'onglet Jump/Rebond.
    pub tab_jump: &'static str,
    /// Libellé de l'onglet Wallix.
    pub tab_wallix: &'static str,

    // ── Toggle verbose ──────────────────────────────────────────────────────
    pub verbose_title: &'static str,
    pub verbose_label: &'static str,

    // ── Barre de recherche ──────────────────────────────────────────────────
    /// Texte affiché dans la barre inactive et vide.
    pub search_idle_hint: &'static str,
    /// Titre du bloc quand la barre est inactive.
    pub search_title_idle: &'static str,
    /// Texte indicatif dans la barre active avant la saisie.
    pub search_placeholder: &'static str,
    /// Titre du bloc actif — `{}` = nombre total de serveurs.
    pub search_title_active: &'static str,
    /// Titre quand aucun résultat — `{}` = terme recherché.
    pub search_no_results: &'static str,
    /// Titre quand tous les serveurs correspondent — `{}` = nombre.
    pub search_all_match: &'static str,
    /// Titre résultats partiels (actif) — `{}` = trouvés, `{}` = total.
    pub search_partial: &'static str,
    /// Titre résultats (non actif) tous affichés — `{}` = nombre.
    pub search_result_all: &'static str,
    /// Titre résultats partiels (non actif) — `{}` = trouvés, `{}` = total, `{}` = terme.
    pub search_result_partial: &'static str,

    // ── Panneaux principaux ─────────────────────────────────────────────────
    pub panel_servers: &'static str,
    pub panel_details: &'static str,
    pub details_placeholder: &'static str,

    // ── Libellés du panneau détails ─────────────────────────────────────────
    pub label_name: &'static str,
    pub label_host: &'static str,
    pub label_port: &'static str,
    pub label_user: &'static str,
    pub label_mode: &'static str,
    pub label_key: &'static str,
    pub label_jump: &'static str,
    pub label_wallix: &'static str,
    pub label_options: &'static str,

    // ── Bloc diagnostic (System) ────────────────────────────────────────────
    pub probe_section: &'static str,
    pub probe_hint: &'static str,
    pub probe_running: &'static str,
    pub probe_kernel: &'static str,
    pub probe_cpu: &'static str,
    /// Nombre de cœurs logiques.
    pub probe_cpu_cores: &'static str,
    /// Nom et version de l'OS.
    pub probe_os: &'static str,
    pub probe_load: &'static str,
    pub probe_ram: &'static str,
    pub probe_disk: &'static str,
    /// Erreur quand le diagnostic est demandé en mode Wallix.
    pub probe_wallix_error: &'static str,
    /// Libellé d'un filesystem supplémentaire présent — `{}` = point de montage.
    pub probe_disk_extra: &'static str,
    /// Ligne complète pour un filesystem absent — `{}` = point de montage.
    pub probe_fs_absent: &'static str,

    // ── Barre de statut ─────────────────────────────────────────────────────
    pub status_normal: &'static str,
    pub status_searching: &'static str,
    pub status_search_active: &'static str,

    // ── Avertissements includes ─────────────────────────────────────────────
    /// `{}` = label, `{}` = chemin, `{}` = erreur
    pub include_warn_load: &'static str,
    /// `{}` = label, `{}` = chemin
    pub include_warn_circular: &'static str,
    /// `{}` = label
    pub include_warn_nested: &'static str,

    // ── Messages de statut (gabarits) ───────────────────────────────────────
    /// `{}` = commande SSH copiée.
    pub copied: &'static str,
    /// `{}` = description de l'erreur.
    pub clipboard_error: &'static str,
    pub clipboard_unavailable: &'static str,
    /// `{}` = description de l'erreur SSH.
    pub ssh_error: &'static str,

    // ── Historique des connexions ────────────────────────────────────────────
    pub last_seen_label: &'static str,
    pub last_seen_never: &'static str,
    /// `{}` = durée formatée (ex. "3 jours")
    pub last_seen_ago: &'static str,
    pub last_seen_just_now: &'static str,

    // ── Rechargement à chaud ─────────────────────────────────────────────────
    /// `{}` = nombre de serveurs
    pub config_reloaded: &'static str,
    pub config_reload_error: &'static str,

    // ── Favoris ──────────────────────────────────────────────────────────────
    pub favorites_title: &'static str,
    pub favorite_added: &'static str,
    pub favorite_removed: &'static str,

    // ── Sort par récence ─────────────────────────────────────────────────────
    pub sort_recent_on: &'static str,
    pub sort_recent_off: &'static str,

    // ── Commande ad-hoc ──────────────────────────────────────────────────────
    pub cmd_prompt: &'static str,
    pub cmd_running: &'static str,
    /// `{}` = exit code
    pub cmd_exit_err: &'static str,

    // ── Validation YAML ──────────────────────────────────────────────────────
    pub validation_title: &'static str,
    /// `{}` = fichier, `{}` = contexte, `{}` = champ
    pub validation_unknown_field: &'static str,

    // ── Tunnels SSH ──────────────────────────────────────────────────────────
    pub tunnel_wallix_unavailable: &'static str,
    /// `{}` = index
    pub tunnel_not_found: &'static str,
    /// `{}` = label, `{}` = port
    pub tunnel_already_active: &'static str,
    /// `{}` = label, `{}` = port
    pub tunnel_started: &'static str,
    /// `{}` = erreur
    pub tunnel_error: &'static str,
    /// `{}` = label, `{}` = port
    pub tunnel_stopped: &'static str,
    /// `{}` = label, `{}` = port, `{}` = raison
    pub tunnel_died: &'static str,
    pub tunnel_deleted: &'static str,
    pub tunnel_updated: &'static str,
    pub tunnel_added: &'static str,
    pub tunnel_overlay_new: &'static str,
    pub tunnel_overlay_hints1: &'static str,
    pub tunnel_overlay_hints2: &'static str,
    /// `{}` = serveur
    pub tunnel_form_edit_title: &'static str,
    /// `{}` = serveur
    pub tunnel_form_new_title: &'static str,
    pub tunnel_form_field_label: &'static str,
    pub tunnel_form_field_local_port: &'static str,
    pub tunnel_form_field_remote_host: &'static str,
    pub tunnel_form_field_remote_port: &'static str,
    pub tunnel_form_hint: &'static str,
    pub tunnel_form_local_port_invalid: &'static str,
    pub tunnel_form_remote_host_empty: &'static str,
    pub tunnel_form_remote_port_invalid: &'static str,
    pub tunnel_badge_label: &'static str,
    /// `{}` = n_actif, `{}` = suffixe pluriel, `{}` = n_cfg, `{}` = suffixe pluriel
    pub tunnel_badge_active: &'static str,
    /// `{}` = n_cfg, `{}` = suffixe pluriel
    pub tunnel_badge_none: &'static str,

    // ── SCP ──────────────────────────────────────────────────────────────────
    pub scp_wallix_unavailable: &'static str,
    pub scp_done_ok: &'static str,
    pub scp_done_err: &'static str,
    /// `{}` = erreur
    pub scp_failed: &'static str,
    pub scp_form_local_required: &'static str,
    pub scp_form_remote_required: &'static str,
    /// `{}` = serveur
    pub scp_direction_title: &'static str,
    pub scp_direction_upload: &'static str,
    pub scp_direction_download: &'static str,
    pub scp_direction_hint: &'static str,
    pub scp_form_field_local: &'static str,
    pub scp_form_field_remote: &'static str,
    pub scp_form_hint: &'static str,
    pub scp_result_title: &'static str,
    /// `{}` = direction.label()
    pub scp_result_success: &'static str,
    /// `{}` = direction.label()
    pub scp_result_errors: &'static str,
    /// `{}` = erreur
    pub scp_result_fail: &'static str,
    pub scp_result_hint: &'static str,
    /// `{}` = direction.label()
    pub scp_in_progress: &'static str,
}

// ─── Français ─────────────────────────────────────────────────────────────────

pub static STRINGS_FR: Strings = Strings {
    error_title: " ⚠  Erreur ",
    error_dismiss: "Appuyez sur Entrée ou Esc pour fermer",

    tab_title: " Mode de Connexion (Tab pour changer) ",
    tab_direct: "Direct [1]",
    tab_jump: "Rebond [2]",
    tab_wallix: "Wallix [3]",

    verbose_title: " Options (v pour basculer) ",
    verbose_label: "Verbose (-v)",

    search_idle_hint: "Appuyez sur / pour rechercher…",
    search_title_idle: " Recherche (/) ",
    search_placeholder: "(nom ou hôte, Échap pour annuler)",
    search_title_active: " 🔍 Recherche nom/hôte ({} serveurs) ",
    search_no_results: " 🔍 Aucun résultat pour '{}' ",
    search_all_match: " 🔍 {} serveurs correspondent ",
    search_partial: " 🔍 {} / {} serveurs ",
    search_result_all: " ✓ {} serveurs affichés ",
    search_result_partial: " ✓ {} / {} correspondent à '{}' ",

    panel_servers: " Serveurs ",
    panel_details: " Détails ",
    details_placeholder: "Sélectionnez un serveur pour voir les détails.",

    label_name: "Nom:    ",
    label_host: "Hôte:   ",
    label_port: "Port:   ",
    label_user: "Util.:  ",
    label_mode: "Mode:   ",
    label_key: "Clé:    ",
    label_jump: "Rebond: ",
    label_wallix: "Wallix:",
    label_options: "Options:",

    probe_section: "─── Système ─────────────────────",
    probe_hint: "  d — diagnostiquer",
    probe_running: "Diagnostic en cours…",
    probe_kernel: "Kernel   ",
    probe_cpu: "CPU      ",
    probe_cpu_cores: "Cœurs    ",
    probe_os: "OS       ",
    probe_load: "Charge   ",
    probe_ram: "RAM",
    probe_disk: "Disk /",
    probe_wallix_error: "Diagnostic non disponible en mode Wallix",
    probe_disk_extra: "Disk {}",
    probe_fs_absent: "⚠  {} — non monté",

    status_normal: "Navigation : ↑/↓ | Ouvrir : Espace/Entrée | Recherche : / | Mode : Tab/1-3 | v : Verbose | y : Copier | d : Probe | f : Favori | F : Vue favs | r : Recharger | x : Cmd | H : Tri | C : Replier tout | q : Quitter",
    status_searching: "Recherche : Tapez pour filtrer… | Échap : Annuler | Ctrl+U : Effacer | Entrée : Valider",
    status_search_active: "Navigation : ↑/↓ | Effacer : Échap | Nouvelle recherche : / | Verbose : v | Entrée : Connecter | q : Quitter",

    include_warn_load: "Impossible de charger '{}' ({}) : {}",
    include_warn_circular: "Dépendance circulaire ignorée : '{}' ({})",
    include_warn_nested: "Les includes imbriqués dans '{}' sont ignorés (v0.7)",

    copied: "Copié : {}",
    clipboard_error: "Erreur presse-papiers : {}",
    clipboard_unavailable: "Presse-papiers indisponible",
    ssh_error: "Erreur SSH : {}",

    last_seen_label: "Dern. conn.: ",
    last_seen_never: "",
    last_seen_ago: "il y a {}",
    last_seen_just_now: "à l'instant",

    config_reloaded: "Config rechargée ({} serveurs)",
    config_reload_error: "Erreur rechargement config",

    favorites_title: " ⭐ Favoris ",
    favorite_added: "⭐ Ajouté aux favoris",
    favorite_removed: "Favori retiré",

    sort_recent_on: "Tri : récent  [H]",
    sort_recent_off: "Tri : alpha   [H]",

    cmd_prompt: "Commande : ",
    cmd_running: "Exécution…",
    cmd_exit_err: "Erreur (exit {})",

    validation_title: " ⚠  Avertissements de configuration ",
    validation_unknown_field: "{} ({}): champ inconnu « {} »",

    tunnel_wallix_unavailable: "Tunnels SSH non disponibles en mode Wallix",
    tunnel_not_found: "Tunnel #{} introuvable pour ce serveur",
    tunnel_already_active: "Tunnel « {} » déjà actif (port {})",
    tunnel_started: "Tunnel « {} » démarré sur le port {}",
    tunnel_error: "Erreur tunnel : {}",
    tunnel_stopped: "Tunnel « {} » (port {}) arrêté",
    tunnel_died: "Tunnel « {} » (port {}) s'est arrêté : {}",
    tunnel_deleted: "Tunnel supprimé",
    tunnel_updated: "Tunnel mis à jour",
    tunnel_added: "Tunnel ajouté",
    tunnel_overlay_new: "+ (nouveau tunnel)",
    tunnel_overlay_hints1: "  ↑↓ naviguer   Enter démarrer/arrêter   Del supprimer",
    tunnel_overlay_hints2: "  e éditer      a ajouter                q/Esc fermer",
    tunnel_form_edit_title: " Modifier le tunnel — {} ",
    tunnel_form_new_title: " Nouveau tunnel — {} ",
    tunnel_form_field_label: "  Label        : ",
    tunnel_form_field_local_port: "  Port local   : ",
    tunnel_form_field_remote_host: "  Hôte distant : ",
    tunnel_form_field_remote_port: "  Port distant : ",
    tunnel_form_hint: "  Tab champ suivant   Enter valider   Esc annuler",
    tunnel_form_local_port_invalid: "Port local invalide (entier 1\u{2013}65535 attendu)",
    tunnel_form_remote_host_empty: "Hôte distant obligatoire",
    tunnel_form_remote_port_invalid: "Port distant invalide (entier 1\u{2013}65535 attendu)",
    tunnel_badge_label: "Tunnels : ",
    tunnel_badge_active: "  {} actif{} / {} configuré{}",
    tunnel_badge_none: "  {} configuré{}, aucun actif",

    scp_wallix_unavailable: "SCP non disponible en mode Wallix",
    scp_done_ok: "SCP terminé ✔",
    scp_done_err: "SCP terminé avec des erreurs ✗",
    scp_failed: "SCP échoué : {}",
    scp_form_local_required: "Le chemin local est obligatoire",
    scp_form_remote_required: "Le chemin distant est obligatoire",
    scp_direction_title: " Transfert SCP — {} ",
    scp_direction_upload: "(local → serveur)",
    scp_direction_download: "(serveur → local)",
    scp_direction_hint: "  Esc annuler",
    scp_form_field_local: "  Local   : ",
    scp_form_field_remote: "  Distant : ",
    scp_form_hint: "  Tab changer de champ   Enter confirmer   Esc annuler",
    scp_result_title: " Résultat SCP ",
    scp_result_success: "SCP {} terminé avec succès",
    scp_result_errors: "SCP {} terminé avec des erreurs",
    scp_result_fail: "Erreur SCP : {}",
    scp_result_hint: "  Enter / Esc  fermer",
    scp_in_progress: "SCP {} en cours...",
};

// ─── Anglais ──────────────────────────────────────────────────────────────────

pub static STRINGS_EN: Strings = Strings {
    error_title: " ⚠  Error ",
    error_dismiss: "Press Enter or Esc to close",

    tab_title: " Connection Mode (Tab to switch) ",
    tab_direct: "Direct [1]",
    tab_jump: "Jump [2]",
    tab_wallix: "Wallix [3]",

    verbose_title: " Options (v to toggle) ",
    verbose_label: "Verbose (-v)",

    search_idle_hint: "Press / to search...",
    search_title_idle: " Search (press /) ",
    search_placeholder: "(search by name or host, ESC to cancel)",
    search_title_active: " 🔍 Search by name/host ({} servers) ",
    search_no_results: " 🔍 No results for '{}' ",
    search_all_match: " 🔍 All {} servers match ",
    search_partial: " 🔍 {} / {} servers ",
    search_result_all: " ✓ Showing all {} servers ",
    search_result_partial: " ✓ {} / {} servers match '{}' ",

    panel_servers: " Servers ",
    panel_details: " Details ",
    details_placeholder: "Select a server to view details.",

    label_name: "Name:   ",
    label_host: "Host:   ",
    label_port: "Port:   ",
    label_user: "User:   ",
    label_mode: "Mode:   ",
    label_key: "Key:    ",
    label_jump: "Jump:   ",
    label_wallix: "Wallix:",
    label_options: "Options:",

    probe_section: "─── System ──────────────────────",
    probe_hint: "  d — probe",
    probe_running: "Running probe…",
    probe_kernel: "Kernel   ",
    probe_cpu: "CPU      ",
    probe_cpu_cores: "Cores    ",
    probe_os: "OS       ",
    probe_load: "Load     ",
    probe_ram: "RAM",
    probe_disk: "Disk /",
    probe_wallix_error: "Probe unavailable in Wallix mode",
    probe_disk_extra: "Disk {}",
    probe_fs_absent: "⚠  {} — not mounted",

    status_normal: "Navigate: ↑/↓ | Expand: Space/Enter | Search: / | Mode: Tab/1-3 | v: Verbose | y: Copy | d: Probe | f: Fav | F: Favs | r: Reload | x: Cmd | H: Sort | C: Collapse all | q: Quit",
    status_searching: "Search Mode: Type to filter | ESC: Cancel | Ctrl+U: Clear | Enter: Apply",
    status_search_active: "Navigate: ↑/↓ | Clear: ESC | New search: / | Verbose: v | Enter: Connect | q: Quit",

    include_warn_load: "Failed to load '{}' ({}) : {}",
    include_warn_circular: "Circular dependency ignored: '{}' ({})",
    include_warn_nested: "Nested includes in '{}' are ignored (v0.7)",

    copied: "Copied: {}",
    clipboard_error: "Clipboard error: {}",
    clipboard_unavailable: "Clipboard unavailable",
    ssh_error: "SSH error: {}",

    last_seen_label: "Last conn.:  ",
    last_seen_never: "",
    last_seen_ago: "{} ago",
    last_seen_just_now: "just now",

    config_reloaded: "Config reloaded ({} servers)",
    config_reload_error: "Config reload error",

    favorites_title: " ⭐ Favorites ",
    favorite_added: "⭐ Added to favorites",
    favorite_removed: "Removed from favorites",

    sort_recent_on: "Sort: recent [H]",
    sort_recent_off: "Sort: alpha  [H]",

    cmd_prompt: "Command: ",
    cmd_running: "Running…",
    cmd_exit_err: "Error (exit {})",

    validation_title: " ⚠  Configuration warnings ",
    validation_unknown_field: "{} ({}): unknown field \"{}\"",

    tunnel_wallix_unavailable: "SSH tunnels unavailable in Wallix mode",
    tunnel_not_found: "Tunnel #{} not found for this server",
    tunnel_already_active: "Tunnel '{}' already active (port {})",
    tunnel_started: "Tunnel '{}' started on port {}",
    tunnel_error: "Tunnel error: {}",
    tunnel_stopped: "Tunnel '{}' (port {}) stopped",
    tunnel_died: "Tunnel '{}' (port {}) died: {}",
    tunnel_deleted: "Tunnel deleted",
    tunnel_updated: "Tunnel updated",
    tunnel_added: "Tunnel added",
    tunnel_overlay_new: "+ (new tunnel)",
    tunnel_overlay_hints1: "  ↑↓ navigate   Enter start/stop   Del delete",
    tunnel_overlay_hints2: "  e edit        a add              q/Esc close",
    tunnel_form_edit_title: " Edit tunnel — {} ",
    tunnel_form_new_title: " New tunnel — {} ",
    tunnel_form_field_label: "  Label       : ",
    tunnel_form_field_local_port: "  Local port  : ",
    tunnel_form_field_remote_host: "  Remote host : ",
    tunnel_form_field_remote_port: "  Remote port : ",
    tunnel_form_hint: "  Tab next field   Enter validate   Esc cancel",
    tunnel_form_local_port_invalid: "Invalid local port (1\u{2013}65535 expected)",
    tunnel_form_remote_host_empty: "Remote host required",
    tunnel_form_remote_port_invalid: "Invalid remote port (1\u{2013}65535 expected)",
    tunnel_badge_label: "Tunnels: ",
    tunnel_badge_active: "  {} active{} / {} configured{}",
    tunnel_badge_none: "  {} configured{}, none active",

    scp_wallix_unavailable: "SCP unavailable in Wallix mode",
    scp_done_ok: "SCP complete ✔",
    scp_done_err: "SCP completed with errors ✗",
    scp_failed: "SCP failed: {}",
    scp_form_local_required: "Local path required",
    scp_form_remote_required: "Remote path required",
    scp_direction_title: " SCP Transfer — {} ",
    scp_direction_upload: "(local → server)",
    scp_direction_download: "(server → local)",
    scp_direction_hint: "  Esc cancel",
    scp_form_field_local: "  Local  : ",
    scp_form_field_remote: "  Remote : ",
    scp_form_hint: "  Tab switch field   Enter confirm   Esc cancel",
    scp_result_title: " SCP Result ",
    scp_result_success: "SCP {} completed successfully",
    scp_result_errors: "SCP {} completed with errors",
    scp_result_fail: "SCP error: {}",
    scp_result_hint: "  Enter / Esc  close",
    scp_in_progress: "SCP {} in progress...",
};

// ─── API publique ─────────────────────────────────────────────────────────────

/// Détecte la langue depuis `LC_ALL` → `LC_MESSAGES` → `LANG`.
/// Retourne [`Lang::Fr`] si la valeur commence par `"fr"`, [`Lang::En`] sinon.
pub fn detect_lang() -> Lang {
    ["LC_ALL", "LC_MESSAGES", "LANG"]
        .iter()
        .find_map(|var| std::env::var(var).ok())
        .map(|val| {
            if val.starts_with("fr") {
                Lang::Fr
            } else {
                Lang::En
            }
        })
        .unwrap_or(Lang::En)
}

/// Retourne la référence statique vers le jeu de chaînes correspondant à `lang`.
pub fn get_strings(lang: Lang) -> &'static Strings {
    match lang {
        Lang::Fr => &STRINGS_FR,
        Lang::En => &STRINGS_EN,
    }
}

/// Substitue les occurrences de `{}` dans `template` par les valeurs de `args`
/// dans l'ordre (première occurrence d'abord).
///
/// # Exemple
/// ```
/// use susshi::i18n::fmt;
/// assert_eq!(fmt("Hello {}!", &["world"]), "Hello world!");
/// ```
pub fn fmt(template: &'static str, args: &[&str]) -> String {
    let mut result = template.to_string();
    for arg in args {
        result = result.replacen("{}", arg, 1);
    }
    result
}

// ─── Tests ────────────────────────────────────────────────────────────────────

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

    /// Exécute `f` après avoir positionné les variables d'env, puis les restaure.
    /// Utilise un mutex pour éviter la concurrence entre tests.
    fn with_env<F: FnOnce()>(vars: &[(&str, Option<&str>)], f: F) {
        use std::sync::Mutex;
        static ENV_LOCK: Mutex<()> = Mutex::new(());
        let _guard = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());

        // On retire d'abord toutes les variables pertinentes pour éviter les
        // interférences avec d'éventuelles valeurs déjà définies dans l'env de test.
        let saved: Vec<(&str, Option<String>)> =
            vars.iter().map(|(k, _)| (*k, env::var(k).ok())).collect();

        for (k, v) in vars {
            match v {
                Some(val) => unsafe { std::env::set_var(k, val) },
                None => unsafe { std::env::remove_var(k) },
            }
        }

        f();

        // Restauration
        for (k, saved_v) in &saved {
            match saved_v {
                Some(v) => unsafe { std::env::set_var(k, v) },
                None => unsafe { std::env::remove_var(k) },
            }
        }
    }

    #[test]
    fn detect_lang_fr() {
        with_env(
            &[
                ("LC_ALL", None),
                ("LC_MESSAGES", None),
                ("LANG", Some("fr_FR.UTF-8")),
            ],
            || {
                assert_eq!(detect_lang(), Lang::Fr);
            },
        );
    }

    #[test]
    fn detect_lang_en() {
        with_env(
            &[
                ("LC_ALL", None),
                ("LC_MESSAGES", None),
                ("LANG", Some("en_US.UTF-8")),
            ],
            || {
                assert_eq!(detect_lang(), Lang::En);
            },
        );
    }

    #[test]
    fn detect_lang_no_env() {
        with_env(
            &[("LC_ALL", None), ("LC_MESSAGES", None), ("LANG", None)],
            || {
                assert_eq!(detect_lang(), Lang::En);
            },
        );
    }

    #[test]
    fn detect_lang_lc_all_takes_priority() {
        with_env(
            &[
                ("LC_ALL", Some("fr_FR.UTF-8")),
                ("LC_MESSAGES", Some("en_US.UTF-8")),
                ("LANG", Some("en_US.UTF-8")),
            ],
            || {
                assert_eq!(detect_lang(), Lang::Fr);
            },
        );
    }

    #[test]
    fn fr_and_en_differ_on_key_strings() {
        let fr = get_strings(Lang::Fr);
        let en = get_strings(Lang::En);

        assert_ne!(fr.error_title, en.error_title);
        assert_ne!(fr.panel_servers, en.panel_servers);
        assert_ne!(fr.status_normal, en.status_normal);
    }

    #[test]
    fn fmt_single_arg() {
        assert_eq!(
            fmt("Copié : {}", &["ssh root@host"]),
            "Copié : ssh root@host"
        );
    }

    #[test]
    fn fmt_two_args() {
        assert_eq!(fmt("{} / {} serveurs", &["3", "10"]), "3 / 10 serveurs");
    }

    #[test]
    fn fmt_three_args() {
        assert_eq!(
            fmt("{} / {} correspondent à '{}'", &["2", "5", "web"]),
            "2 / 5 correspondent à 'web'"
        );
    }
}