forked from Anri/cal8tor
let user custom the cell length
This commit is contained in:
parent
744198e66e
commit
b1f488264d
3 changed files with 17 additions and 16 deletions
|
@ -20,6 +20,10 @@ struct Args {
|
||||||
/// Export to iCalendar format (.ics)
|
/// Export to iCalendar format (.ics)
|
||||||
#[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 the timetable)
|
||||||
|
#[clap(short, long, value_name = "CELL LENGTH", default_value_t = 35)]
|
||||||
|
cl: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -68,7 +72,7 @@ async fn main() {
|
||||||
} else {
|
} else {
|
||||||
// Show the calendar
|
// Show the calendar
|
||||||
println!("Affichage...");
|
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.");
|
println!("Vous devrez peut-être mettre votre terminal en plein écran si ce n'est pas déjà le cas.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,20 +328,18 @@ fn get_semester(semester: Option<i8>, letter: Option<char>) -> i8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Display the timetable
|
/// Display the timetable
|
||||||
pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>)), cell_length: usize) {
|
||||||
// Cell length
|
|
||||||
let cl = 35;
|
|
||||||
// Cell length for hours
|
// Cell length for hours
|
||||||
let clh = 11;
|
let clh = 11;
|
||||||
// Cell number
|
// Cell number
|
||||||
let cn = 6;
|
let cn = 6;
|
||||||
// 3/4 of cell length
|
// 3/4 of cell length
|
||||||
let quarter = (3 * cl) / 4;
|
let quarter = (3 * cell_length) / 4;
|
||||||
|
|
||||||
let sep = TabChar::Bv.val();
|
let sep = TabChar::Bv.val();
|
||||||
|
|
||||||
// Top of the tab
|
// 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
|
// First empty case
|
||||||
print!("{}{:^clh$}{}", sep, "", sep);
|
print!("{}{:^clh$}{}", sep, "", sep);
|
||||||
|
@ -350,7 +348,7 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
||||||
let mut days = HashMap::new();
|
let mut days = HashMap::new();
|
||||||
for (i, data) in (&timetable.1 .1).iter().enumerate() {
|
for (i, data) in (&timetable.1 .1).iter().enumerate() {
|
||||||
days.insert(i, &data.name);
|
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
|
// Store the data of the course for utils::line_table
|
||||||
|
@ -358,7 +356,7 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
||||||
// For each hours -- i the hour's number
|
// For each hours -- i the hour's number
|
||||||
for (i, hour) in timetable.0.into_iter().enumerate() {
|
for (i, hour) in timetable.0.into_iter().enumerate() {
|
||||||
// Draw separator line
|
// 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
|
// Reset
|
||||||
next_skip = HashMap::new();
|
next_skip = HashMap::new();
|
||||||
|
@ -384,10 +382,10 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
||||||
if course.name.len() > quarter {
|
if course.name.len() > quarter {
|
||||||
let data = utils::split_half(&course.name);
|
let data = utils::split_half(&course.name);
|
||||||
next_skip.insert(j, data.1.trim());
|
next_skip.insert(j, data.1.trim());
|
||||||
print!("{}{:^cl$}", sep, data.0.trim());
|
print!("{}{:^cell_length$}", sep, data.0.trim());
|
||||||
} else {
|
} else {
|
||||||
next_skip.insert(j, &course.name);
|
next_skip.insert(j, &course.name);
|
||||||
print!("{}{:^cl$}", sep, "");
|
print!("{}{:^cell_length$}", sep, "");
|
||||||
}
|
}
|
||||||
info_slot = true;
|
info_slot = true;
|
||||||
break;
|
break;
|
||||||
|
@ -395,9 +393,9 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
||||||
// Else simply print the course
|
// Else simply print the course
|
||||||
// If the data is too long
|
// If the data is too long
|
||||||
if course.name.len() > quarter {
|
if course.name.len() > quarter {
|
||||||
print!("{}{:^cl$}", sep, utils::etc_str(&course.name));
|
print!("{}{:^cell_length$}", sep, utils::etc_str(&course.name));
|
||||||
} else {
|
} else {
|
||||||
print!("{}{:^cl$}", sep, &course.name);
|
print!("{}{:^cell_length$}", sep, &course.name);
|
||||||
}
|
}
|
||||||
info_slot = true;
|
info_slot = true;
|
||||||
break;
|
break;
|
||||||
|
@ -409,7 +407,7 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
||||||
// Verify the "no course" is in the correct day and hour
|
// Verify the "no course" is in the correct day and hour
|
||||||
if *days.get(&j).unwrap() == &day.name.to_string() && k == i {
|
if *days.get(&j).unwrap() == &day.name.to_string() && k == i {
|
||||||
// If yes print empty row because there is no course
|
// If yes print empty row because there is no course
|
||||||
print!("{}{:^cl$}", sep, "");
|
print!("{}{:^cell_length$}", sep, "");
|
||||||
info_slot = true;
|
info_slot = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -420,11 +418,11 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
|
||||||
if !info_slot {
|
if !info_slot {
|
||||||
// We found nothing about the slot because the precedent course
|
// We found nothing about the slot because the precedent course
|
||||||
// takes more place than one slot
|
// takes more place than one slot
|
||||||
print!("{}{:^cl$}", sep, "");
|
print!("{}{:^cell_length$}", sep, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print!("{}", sep);
|
print!("{}", sep);
|
||||||
}
|
}
|
||||||
// Bottom of the table
|
// 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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,6 @@ pub fn split_half(text: &str) -> (&str, &str) {
|
||||||
text.split_at(mid)
|
text.split_at(mid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Reduce size of string by adding etc. to it, and cutting some info
|
// Reduce size of string by adding etc. to it, and cutting some info
|
||||||
pub fn etc_str(text: &str) -> String {
|
pub fn etc_str(text: &str) -> String {
|
||||||
format!("{}...", split_half(text).0.trim())
|
format!("{}...", split_half(text).0.trim())
|
||||||
|
|
Loading…
Reference in a new issue