vtcode_commons/
modal_hints.rs1pub const APPROVAL_NAVIGATE_DENY: &str = "Use ↑↓ or Tab to navigate • Enter to select • Esc to deny";
10pub const APPROVAL_NAVIGATE_CANCEL: &str = "Use ↑↓ or Tab to navigate • Enter to select • Esc to cancel";
12pub const APPROVAL_NAVIGATE_STOP: &str = "Use ↑↓ or Tab to navigate • Enter to select • Esc to stop";
14
15pub const MODEL_PICKER_NAVIGATE_FILTER: &str =
17 "Use ↑↓ or Tab to navigate • Enter to select • Type to filter • Esc to cancel";
18pub const MODEL_PICKER_FOLLOW_UP_HINT: &str =
25 "Use ↑↓ or Tab to navigate • Enter to select • ← Back to model list • Esc cancels the picker";
26
27pub fn choose_handling_line(object: &str) -> String {
29 format!("Choose how to handle {object}:")
30}
31
32pub fn truncate_modal_text(text: &str, max_chars: usize) -> String {
38 crate::formatting::truncate_within(text, max_chars, "…")
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn approval_hints_share_navigation_prefix_but_differ_by_exit_verb() {
47 for hint in [APPROVAL_NAVIGATE_DENY, APPROVAL_NAVIGATE_CANCEL, APPROVAL_NAVIGATE_STOP] {
48 assert!(hint.starts_with("Use ↑↓ or Tab to navigate • Enter to select • Esc to "));
49 }
50 assert!(APPROVAL_NAVIGATE_DENY.ends_with("deny"));
51 assert!(APPROVAL_NAVIGATE_CANCEL.ends_with("cancel"));
52 assert!(APPROVAL_NAVIGATE_STOP.ends_with("stop"));
53 }
54
55 #[test]
56 fn model_picker_hints_share_navigation_prefix() {
57 for hint in [MODEL_PICKER_NAVIGATE_FILTER, MODEL_PICKER_FOLLOW_UP_HINT] {
58 assert!(hint.starts_with("Use ↑↓ or Tab to navigate • Enter to "));
59 }
60 assert!(MODEL_PICKER_NAVIGATE_FILTER.contains("Type to filter"));
61 assert!(MODEL_PICKER_FOLLOW_UP_HINT.contains("Back to model list"));
62 assert!(MODEL_PICKER_FOLLOW_UP_HINT.contains("Esc"));
63 }
64
65 #[test]
66 fn choose_handling_line_interpolates_object_as_sentence() {
67 assert_eq!(choose_handling_line("this tool"), "Choose how to handle this tool:");
68 assert_eq!(
69 choose_handling_line("workspace lifecycle hooks"),
70 "Choose how to handle workspace lifecycle hooks:"
71 );
72 }
73
74 #[test]
75 fn truncate_modal_text_marks_truncation_with_ellipsis_only_when_shortened() {
76 assert_eq!(truncate_modal_text("short", 10), "short");
77 assert_eq!(truncate_modal_text("exactly-ten", 11), "exactly-ten");
78 assert_eq!(truncate_modal_text("over the limit text", 10), "over the …");
79 }
80
81 #[test]
82 fn truncate_modal_text_matches_the_canonical_truncate_within_at_every_boundary() {
83 for text in ["", "a", "short", "over the limit text", "あいうえお"] {
85 for max_chars in 0..=12 {
86 assert_eq!(
87 truncate_modal_text(text, max_chars),
88 crate::formatting::truncate_within(text, max_chars, "…"),
89 "text {text:?} at max_chars {max_chars}"
90 );
91 }
92 }
93 }
94}