-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathautocomplete_basic.rs
More file actions
48 lines (44 loc) · 1.27 KB
/
Copy pathautocomplete_basic.rs
File metadata and controls
48 lines (44 loc) · 1.27 KB
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
use demand::Input;
fn main() {
let input = Input::new("Select a programming language:")
.description("Start typing to see suggestions")
.placeholder("e.g., rust, python, zig")
.autocomplete_fn(|input| {
let languages = [
"rust",
"python",
"typescript",
"go",
"java",
"c",
"c++",
"c#",
"ruby",
"swift",
"kotlin",
"scala",
"haskell",
"elixir",
"clojure",
"zig",
];
let suggestions: Vec<String> = languages
.iter()
.filter(|lang| {
input.is_empty() || lang.to_lowercase().contains(&input.to_lowercase())
})
.map(|s| s.to_string())
.collect();
Ok(suggestions)
});
match input.run() {
Ok(language) => println!("You selected: {}", language),
Err(e) => {
if e.kind() == std::io::ErrorKind::Interrupted {
println!("Cancelled");
} else {
panic!("Error: {}", e);
}
}
}
}