From 77c2444de1d71b820f0d3e0ede6ab1a0816ffd50 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 1 Jan 2024 11:24:27 +0100 Subject: [PATCH] don't crash when the selected courses don't have multiples TP/TD options --- src/filter.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/filter.rs b/src/filter.rs index 5568b9b..24008ea 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -104,13 +104,16 @@ fn tdtp(timetable: &mut Timetable) { let mut multiselected: Vec = td_or_tp.iter().map(get_selection).collect(); multiselected.sort(); - let defaults = vec![false; multiselected.len()]; - let selections = MultiSelect::new() - .with_prompt(format!("Choisis tes horaires de TD/TP {}", DISCLAIMER)) - .items(&multiselected[..]) - .defaults(&defaults[..]) - .interact() - .unwrap(); + let mut selections = vec![]; + if !multiselected.is_empty() { + let defaults = vec![false; multiselected.len()]; + selections = MultiSelect::new() + .with_prompt(format!("Choisis tes horaires de TD/TP {}", DISCLAIMER)) + .items(&multiselected[..]) + .defaults(&defaults[..]) + .interact() + .unwrap(); + } // Keep only wanted courses for day in &mut timetable.1 .1 {