diff --git a/src/main.rs b/src/main.rs index e0dd2f9..e8ff4e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,10 @@ struct Args { /// Export to iCalendar format (.ics) #[clap(short, long, value_name = "FILE NAME")] export: Option, + + /// Size of cell of the timetable (irrelevant when exporting the timetable) + #[clap(short, long, value_name = "CELL LENGTH", default_value_t = 35)] + cl: usize, } #[tokio::main] @@ -68,7 +72,7 @@ async fn main() { } else { // Show the calendar println!("Affichage..."); - timetable::display(timetable); + timetable::display(timetable, args.cl); println!("Vous devrez peut-être mettre votre terminal en plein écran si ce n'est pas déjà le cas."); } } diff --git a/src/timetable.rs b/src/timetable.rs index 636bc10..7b0e74c 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -328,20 +328,18 @@ fn get_semester(semester: Option, letter: Option) -> i8 { } /// Display the timetable -pub fn display(timetable: (Vec, (usize, Vec))) { - // Cell length - let cl = 35; +pub fn display(timetable: (Vec, (usize, Vec)), cell_length: usize) { // Cell length for hours let clh = 11; // Cell number let cn = 6; // 3/4 of cell length - let quarter = (3 * cl) / 4; + let quarter = (3 * cell_length) / 4; let sep = TabChar::Bv.val(); // Top of the tab - utils::line_table(clh, cl, cn, Position::Top, HashMap::new()); + utils::line_table(clh, cell_length, cn, Position::Top, HashMap::new()); // First empty case print!("{}{:^clh$}{}", sep, "", sep); @@ -350,7 +348,7 @@ pub fn display(timetable: (Vec, (usize, Vec))) { let mut days = HashMap::new(); for (i, data) in (&timetable.1 .1).iter().enumerate() { days.insert(i, &data.name); - print!("{:^cl$}{}", &data.name, sep); + print!("{:^cell_length$}{}", &data.name, sep); } // Store the data of the course for utils::line_table @@ -358,7 +356,7 @@ pub fn display(timetable: (Vec, (usize, Vec))) { // For each hours -- i the hour's number for (i, hour) in timetable.0.into_iter().enumerate() { // Draw separator line - utils::line_table(clh, cl, cn, Position::Middle, next_skip); + utils::line_table(clh, cell_length, cn, Position::Middle, next_skip); // Reset next_skip = HashMap::new(); @@ -384,10 +382,10 @@ pub fn display(timetable: (Vec, (usize, Vec))) { if course.name.len() > quarter { let data = utils::split_half(&course.name); next_skip.insert(j, data.1.trim()); - print!("{}{:^cl$}", sep, data.0.trim()); + print!("{}{:^cell_length$}", sep, data.0.trim()); } else { next_skip.insert(j, &course.name); - print!("{}{:^cl$}", sep, ""); + print!("{}{:^cell_length$}", sep, ""); } info_slot = true; break; @@ -395,9 +393,9 @@ pub fn display(timetable: (Vec, (usize, Vec))) { // Else simply print the course // If the data is too long if course.name.len() > quarter { - print!("{}{:^cl$}", sep, utils::etc_str(&course.name)); + print!("{}{:^cell_length$}", sep, utils::etc_str(&course.name)); } else { - print!("{}{:^cl$}", sep, &course.name); + print!("{}{:^cell_length$}", sep, &course.name); } info_slot = true; break; @@ -409,7 +407,7 @@ pub fn display(timetable: (Vec, (usize, Vec))) { // Verify the "no course" is in the correct day and hour if *days.get(&j).unwrap() == &day.name.to_string() && k == i { // If yes print empty row because there is no course - print!("{}{:^cl$}", sep, ""); + print!("{}{:^cell_length$}", sep, ""); info_slot = true; break; } @@ -420,11 +418,11 @@ pub fn display(timetable: (Vec, (usize, Vec))) { if !info_slot { // We found nothing about the slot because the precedent course // takes more place than one slot - print!("{}{:^cl$}", sep, ""); + print!("{}{:^cell_length$}", sep, ""); } } print!("{}", sep); } // Bottom of the table - utils::line_table(clh, cl, cn, Position::Bottom, HashMap::new()); + utils::line_table(clh, cell_length, cn, Position::Bottom, HashMap::new()); } diff --git a/src/utils.rs b/src/utils.rs index 1d49b34..cd74386 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -95,7 +95,6 @@ pub fn split_half(text: &str) -> (&str, &str) { text.split_at(mid) } - // Reduce size of string by adding etc. to it, and cutting some info pub fn etc_str(text: &str) -> String { format!("{}...", split_half(text).0.trim())