-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathselect.rs
More file actions
31 lines (27 loc) · 858 Bytes
/
select.rs
File metadata and controls
31 lines (27 loc) · 858 Bytes
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
use dialoguer::{theme::ColorfulTheme, Select};
use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;
#[test]
fn basic_navigation_produces_correct_selection() {
let selections = &[
"Ice Cream",
"Vanilla Cupcake",
"Chocolate Muffin",
"A Pile of sweet, sweet mustard",
];
let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Optionally pick your flavor")
.set_before(|| {
let mut enigo = Enigo::new();
enigo.key_click(Key::Layout('j'));
enigo.key_down(Key::Return);
thread::sleep(Duration::from_millis(10));
enigo.key_up(Key::Return);
})
.default(0)
.items(&selections[..])
.interact_opt()
.unwrap();
assert_eq!(Some(1), selection);
}