Redo watch but with only the homework that has been given out pass on the way here the subset
(exercises: &[Exercise], verbose: bool, homework_number: String)
| 214 | // Redo watch but with only the homework that has been given out |
| 215 | // pass on the way here the subset |
| 216 | fn homework(exercises: &[Exercise], verbose: bool, homework_number: String) -> notify::Result<WatchStatus> { |
| 217 | |
| 218 | /* Clears the terminal with an ANSI escape code. |
| 219 | Works in UNIX and newer Windows terminals. */ |
| 220 | fn clear_screen() { |
| 221 | println!("\x1Bc"); |
| 222 | } |
| 223 | |
| 224 | println!("exercises: {:?}", exercises); |
| 225 | println!("exercise[0]: {:?}", exercises.len()); |
| 226 | |
| 227 | let (tx, rx) = channel(); |
| 228 | let should_quit = Arc::new(AtomicBool::new(false)); |
| 229 | |
| 230 | // load from the other dir |
| 231 | let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?; |
| 232 | |
| 233 | // watch for changes anywhere in this folder (TODO check subdir check) |
| 234 | watcher.watch(Path::new("./homeworks"), RecursiveMode::Recursive)?; // I think watcher looks for file changes |
| 235 | clear_screen(); |
| 236 | |
| 237 | let mut homework_path: String = "./homeworks/homework".to_owned(); |
| 238 | homework_path.push_str(&homework_number); |
| 239 | |
| 240 | let to_owned_hint = |t: &Exercise| t.hint.to_owned(); |
| 241 | |
| 242 | // Check if directory exists |
| 243 | let b = Path::new(&homework_path).is_dir(); //.is_file(); |
| 244 | |
| 245 | // Filter against what's in the dirctory for number 1 |
| 246 | let paths = fs::read_dir(homework_path).expect("Can't find homework. Have you run the wrong homework number?"); |
| 247 | |
| 248 | // Vec of things that are present in this homework |
| 249 | let mut exercise_names: Vec<String> = Vec::new(); |
| 250 | |
| 251 | for path in paths { |
| 252 | let strr: String = path.unwrap().path().display().to_string(); |
| 253 | let res: Vec<String> = strr.split("/").map(|s| s.to_string()).collect(); |
| 254 | exercise_names.push(res.last().unwrap().clone()); |
| 255 | } |
| 256 | |
| 257 | let mut exercises_filtered: Vec<exercise::Exercise> = Vec::new(); |
| 258 | |
| 259 | println!("\n"); |
| 260 | |
| 261 | // filter out from the exercises list. |
| 262 | // Include based on matching homework subdirectories |
| 263 | for exercise in exercises { |
| 264 | |
| 265 | let path_string: String = exercise.path.clone().into_os_string().into_string().unwrap(); |
| 266 | let path_elements: Vec<&str> = path_string.split('/').collect(); |
| 267 | |
| 268 | if path_elements.len() > 3{ |
| 269 | |
| 270 | let exercise_dir: String = String::from(path_elements.clone()[2]); |
| 271 | |
| 272 | // retrieve 3rd variable from teh path and check for match |
| 273 | if exercise_names.contains(&exercise_dir) { |
no test coverage detected