MCPcopy Create free account
hub / github.com/emberian/evdev / pick_device

Function pick_device

examples/_pick_device.rs:5–26  ·  view source on GitHub ↗

An arg parser/prompt shared between the `evtest*` examples. Also demonstrates opening/finding connected devices.

()

Source from the content-addressed store, hash-verified

3//! connected devices.
4
5pub fn pick_device() -> evdev::Device {
6 use std::io::prelude::*;
7
8 let mut args = std::env::args_os();
9 args.next();
10 if let Some(dev_file) = args.next() {
11 evdev::Device::open(dev_file).unwrap()
12 } else {
13 let mut devices = evdev::enumerate().map(|t| t.1).collect::<Vec<_>>();
14 // readdir returns them in reverse order from their eventN names for some reason
15 devices.reverse();
16 for (i, d) in devices.iter().enumerate() {
17 println!("{}: {}", i, d.name().unwrap_or("Unnamed device"));
18 }
19 print!("Select the device [0-{}]: ", devices.len());
20 let _ = std::io::stdout().flush();
21 let mut chosen = String::new();
22 std::io::stdin().read_line(&mut chosen).unwrap();
23 let n = chosen.trim().parse::<usize>().unwrap();
24 devices.into_iter().nth(n).unwrap()
25 }
26}
27
28fn main() {}

Callers 5

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 4

iterMethod · 0.80
into_iterMethod · 0.80
enumerateFunction · 0.50
nextMethod · 0.45

Tested by 3

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…