forked from Anri/cal8tor
todo
This commit is contained in:
parent
65072feb2c
commit
51f0657c13
3 changed files with 5 additions and 156 deletions
|
@ -27,10 +27,6 @@ struct Args {
|
||||||
#[clap(short, long, value_name = "FILE NAME")]
|
#[clap(short, long, value_name = "FILE NAME")]
|
||||||
export: Option<String>,
|
export: Option<String>,
|
||||||
|
|
||||||
/// Size of cell of the timetable (irrelevant when exporting)
|
|
||||||
#[clap(short, long, value_name = "CELL LENGTH", default_value_t = 35)]
|
|
||||||
cl: usize,
|
|
||||||
|
|
||||||
/// Doesn't distinguish TD from TP
|
/// Doesn't distinguish TD from TP
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
td_are_tp: bool,
|
td_are_tp: bool,
|
||||||
|
@ -90,6 +86,6 @@ async fn main() {
|
||||||
} else {
|
} else {
|
||||||
// Show the calendar
|
// Show the calendar
|
||||||
println!("Affichage...");
|
println!("Affichage...");
|
||||||
timetable::display(&timetable, args.cl);
|
timetable::display(&timetable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
103
src/timetable.rs
103
src/timetable.rs
|
@ -6,8 +6,8 @@ use scraper::Selector;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
self, get_hours, get_semester, get_webpage, get_year,
|
get_hours, get_semester, get_webpage, get_year,
|
||||||
models::{Info, InfoList, Position, TabChar},
|
models::{Info, InfoList},
|
||||||
Capitalize,
|
Capitalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -271,101 +271,6 @@ fn add_courses(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Display the timetable
|
/// Display the timetable
|
||||||
pub fn display(timetable: &(Arc<[String]>, (usize, Vec<models::Day>)), cell_length: usize) {
|
pub fn display(timetable: &(Arc<[String]>, (usize, Vec<models::Day>))) {
|
||||||
// Cell length for hours
|
todo!("{:#?}", timetable)
|
||||||
let clh = 11;
|
|
||||||
// Cell number
|
|
||||||
let cn = 6;
|
|
||||||
// 3/4 of cell length
|
|
||||||
let quarter = (3 * cell_length) / 4;
|
|
||||||
|
|
||||||
let sep = TabChar::Bv.val();
|
|
||||||
|
|
||||||
// Top of the tab
|
|
||||||
utils::line_table(clh, cell_length, cn, &Position::Top, &HashMap::new());
|
|
||||||
|
|
||||||
// First empty case
|
|
||||||
print!("{}{:^clh$}{}", sep, "", sep);
|
|
||||||
|
|
||||||
// Print day's of the week
|
|
||||||
let mut days = HashMap::new();
|
|
||||||
for (i, data) in timetable.1 .1.iter().enumerate() {
|
|
||||||
days.insert(i, &data.name);
|
|
||||||
print!("{:^cell_length$}{}", &data.name, sep);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the data of the course for utils::line_table
|
|
||||||
let mut next_skip = HashMap::new();
|
|
||||||
// For each hours -- i the hour's number
|
|
||||||
for (i, hour) in timetable.0.iter().enumerate() {
|
|
||||||
// Draw separator line
|
|
||||||
utils::line_table(clh, cell_length, cn, &Position::Middle, &next_skip);
|
|
||||||
|
|
||||||
// Reset
|
|
||||||
next_skip = HashMap::new();
|
|
||||||
|
|
||||||
// Print hour
|
|
||||||
print!("{sep}{hour:^clh$}");
|
|
||||||
|
|
||||||
// For all the days - `j` the day's number
|
|
||||||
for (j, day) in timetable.1 .1.iter().enumerate() {
|
|
||||||
// True if we found something about the slot we are looking for
|
|
||||||
let mut info_slot = false;
|
|
||||||
|
|
||||||
// For all the courses of each days - `k` the possible course.start
|
|
||||||
for (k, course_opt) in day.courses.iter().enumerate() {
|
|
||||||
match course_opt {
|
|
||||||
// If there is a course
|
|
||||||
Some(course) => {
|
|
||||||
// Check the course's hour
|
|
||||||
if i == course.start {
|
|
||||||
// If the course uses more than one time slot
|
|
||||||
if course.size > 1 {
|
|
||||||
// If the data is too long
|
|
||||||
if course.name.len() > quarter {
|
|
||||||
let data = utils::split_half(&course.name);
|
|
||||||
next_skip.insert(j, data.1.trim());
|
|
||||||
print!("{}{:^cell_length$}", sep, data.0.trim());
|
|
||||||
} else {
|
|
||||||
next_skip.insert(j, &course.name);
|
|
||||||
print!("{}{:^cell_length$}", sep, "");
|
|
||||||
}
|
|
||||||
info_slot = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Else simply print the course
|
|
||||||
// If the data is too long
|
|
||||||
if course.name.len() > quarter {
|
|
||||||
print!("{}{:^cell_length$}", sep, utils::etc_str(&course.name));
|
|
||||||
} else {
|
|
||||||
print!("{}{:^cell_length$}", sep, &course.name);
|
|
||||||
}
|
|
||||||
info_slot = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If no course was found
|
|
||||||
None => {
|
|
||||||
// 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!("{}{:^cell_length$}", sep, "");
|
|
||||||
info_slot = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Else it was a course of another day/time
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if !info_slot {
|
|
||||||
// We found nothing about the slot because the precedent course
|
|
||||||
// takes more place than one slot
|
|
||||||
print!("{}{:^cell_length$}", sep, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print!("{sep}");
|
|
||||||
}
|
|
||||||
// Bottom of the table
|
|
||||||
utils::line_table(clh, cell_length, cn, &Position::Bottom, &HashMap::new());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,58 +2,6 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
|
||||||
/// Collection of char for the table
|
|
||||||
pub enum TabChar {
|
|
||||||
/// Vertical bar
|
|
||||||
Bv,
|
|
||||||
/// Horizontal bar
|
|
||||||
Bh,
|
|
||||||
/// Joint left
|
|
||||||
Jl,
|
|
||||||
/// Joint right
|
|
||||||
Jr,
|
|
||||||
/// Joint bottom left
|
|
||||||
Jbl,
|
|
||||||
/// Joint bottom right
|
|
||||||
Jbr,
|
|
||||||
/// Joint top left
|
|
||||||
Jtl,
|
|
||||||
/// Joint top right
|
|
||||||
Jtr,
|
|
||||||
/// Joint to top
|
|
||||||
Jtt,
|
|
||||||
/// Joint to bottom
|
|
||||||
Jtb,
|
|
||||||
/// Joint of the middle
|
|
||||||
Jm,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TabChar {
|
|
||||||
/// Value of the element
|
|
||||||
pub fn val(&self) -> char {
|
|
||||||
match *self {
|
|
||||||
Self::Bv => '│',
|
|
||||||
Self::Bh => '─',
|
|
||||||
Self::Jl => '├',
|
|
||||||
Self::Jr => '┤',
|
|
||||||
Self::Jbl => '└',
|
|
||||||
Self::Jbr => '┘',
|
|
||||||
Self::Jtl => '┌',
|
|
||||||
Self::Jtr => '┐',
|
|
||||||
Self::Jtt => '┴',
|
|
||||||
Self::Jtb => '┬',
|
|
||||||
Self::Jm => '┼',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Position for lines inside the table
|
|
||||||
pub enum Position {
|
|
||||||
Top,
|
|
||||||
Middle,
|
|
||||||
Bottom,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type InfoList = Vec<(chrono::DateTime<Utc>, i64)>;
|
pub type InfoList = Vec<(chrono::DateTime<Utc>, i64)>;
|
||||||
|
|
||||||
pub struct InfoType {
|
pub struct InfoType {
|
||||||
|
|
Loading…
Reference in a new issue