/// Create a new Node by asking the user for data and scanning.
Create a new Node by asking the user for data and scanning.
Create a new Node by asking the user for data and scanning .
fn acquire() -> Result<Node, Box<dyn Error>> {
	   println!("New measurement properties:");
	   // Prompt user for position
        let mut position = Coordinate::new();
	   let mut get_pos_done = false;
        while !get_pos_done {
            print!("    Coordinates (x y z): ");
            stdout().flush().expect("failed to flush stdout");
            let mut pos_str = String::new();
            stdin().read_line(&mut pos_str).expect("failed to read input");
            pos_str = pos_str.replace("\n", "");
            let parts: Vec<&str> = pos_str.split(" ").collect();
            if parts.len() != 3 {
                println!("    Error: Must be in format \"x y z\"");
                continue;
            }
		  position.x = match parts[0].parse::<f32>() {
			 Ok(v) => v,
			 Err(e) => {
				println!("    Error: Failed to parse x as float: {}", e);
				continue;
			 },
		  };
		  position.y = match parts[1].parse::<f32>() {
			 Ok(v) => v,
			 Err(e) => {
				println!("    Error: Failed to parse y as float: {}", e);
				continue;
			 },
		  };
		  position.z = match parts[2].parse::<f32>() {
			 Ok(v) => v,
			 Err(e) => {
				println!("    Error: Failed to parse z as float: {}", e);
				continue;
			 },
		  };
            get_pos_done = true;
        }
        // Prompt user for notes
        print!("    Notes (empty for none): ");
        let mut notes = String::new();
        stdout().flush().expect("failed to flush stdout");
        stdin().read_line(&mut notes).expect("failed to read input");
        notes = notes.replace("\n", "");
        // Scan networks
	   println!("Scanning");
	   let mut networks = Network::scan()?;
	   networks.sort_by_key(|n| n.mac.clone());
	   if networks.len() == 0 {
		  println!("Warning: No networks were found, this indicates that you may have to run this tool with elevated privileges");
	   }
	   let mut ssid_max_len = 0;
	   for network in &networks {
		  if network.ssid.len() > ssid_max_len {
			 ssid_max_len = network.ssid.len();
		  }
	   }
	   let mut ssid_len_match = Vec::<Network>::new();
	   for network in &networks {
		  let mut matched = network.clone();
		  while matched.ssid.len() < ssid_max_len {
			 matched.ssid += " ";
		  }
		  ssid_len_match.push(matched);
	   }
	   let networks_plural_str = match networks.len() != 1 {
		  true => "s",
		  false => "",
	   };
	   println!("Measured {} network{}:", networks.len(), networks_plural_str);
	   for network in &ssid_len_match {
		  println!("    {}", network);
	   }
        Ok(Node{
            position: position,
            notes: notes,
            networks: networks,
        })
    }
fn acquire ( ) -> Result < Node , Box < dyn Error > > { println ! ( " " ) ; // Prompt user for position let mut position = Coordinate :: new ( ) ; let mut get_pos_done = false ; while ! get_pos_done { print ! ( " " ) ; stdout ( ) . flush ( ) . expect ( " " ) ; let mut pos_str = String :: new ( ) ; stdin ( ) . read_line ( & mut pos_str ) . expect ( " " ) ; pos_str = pos_str . replace ( " \n " , " " ) ; let parts : Vec < & str > = pos_str . split ( " " ) . collect ( ) ; if parts . len ( ) != 3 { println ! ( " \" \" " ) ; continue ; } position . x = match parts [ 0 ] . parse :: < f32 > ( ) { Ok ( v ) => v , Err ( e ) => { println ! ( " " e ) ; continue ; } , } ; position . y = match parts [ 1 ] . parse :: < f32 > ( ) { Ok ( v ) => v , Err ( e ) => { println ! ( " " e ) ; continue ; } , } ; position . z = match parts [ 2 ] . parse :: < f32 > ( ) { Ok ( v ) => v , Err ( e ) => { println ! ( " " e ) ; continue ; } , } ; get_pos_done = true ; } // Prompt user for notes print ! ( " " ) ; let mut notes = String :: new ( ) ; stdout ( ) . flush ( ) . expect ( " " ) ; stdin ( ) . read_line ( & mut notes ) . expect ( " " ) ; notes = notes . replace ( " \n " , " " ) ; // Scan networks println ! ( " " ) ; let mut networks = Network :: scan ( ) ? ; networks . sort_by_key ( | n | n . mac . clone ( ) ) ; if networks . len ( ) == 0 { println ! ( " " ) ; } let mut ssid_max_len = 0 ; for network in & networks { if network . ssid . len ( ) > ssid_max_len { ssid_max_len = network . ssid . len ( ) ; } } let mut ssid_len_match = Vec :: < Network > :: new ( ) ; for network in & networks { let mut matched = network . clone ( ) ; while matched . ssid . len ( ) < ssid_max_len { matched . ssid += " " ; } ssid_len_match . push ( matched ) ; } let networks_plural_str = match networks . len ( ) != 1 { true => " " , false => " " , } ; println ! ( " " networks len ( ) networks_plural_str ) ; for network in & ssid_len_match { println ! ( " " network ) ; } Ok ( Node { position : position , notes : notes , networks : networks , } ) }
Create a new Node by asking the user for data and scanning.
Create a new Node by asking the user for data and scanning .