Archived
1
0
Fork 0
forked from Anri/cal8tor

make the table more readable

This commit is contained in:
Mylloon 2022-08-23 18:30:01 +02:00
parent 2f42d4de91
commit cbc17ba85d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 36 additions and 4 deletions

View file

@ -335,6 +335,8 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
let clh = 11;
// Cell number
let cn = 6;
// 3/4 of cell length
let quarter = (3 * cl) / 4;
let sep = TabChar::Bv.val();
@ -376,15 +378,27 @@ pub fn display(timetable: (Vec<String>, (usize, Vec<models::Day>))) {
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 course uses more than one time slot
next_skip.insert(j, &course.name);
print!("{}{:^cl$}", sep, "");
// If the data is too long
if course.name.len() > quarter {
let data = utils::split_half(&course.name);
next_skip.insert(j, data.1);
print!("{}{:^cl$}", sep, data.0);
} else {
next_skip.insert(j, &course.name);
print!("{}{:^cl$}", sep, "");
}
info_slot = true;
break;
} else {
// Else simply print the course
print!("{}{:^cl$}", sep, &course.name);
// If the data is too long
if course.name.len() > quarter {
print!("{}{:^cl$}", sep, utils::etc_str(&course.name));
} else {
print!("{}{:^cl$}", sep, &course.name);
}
info_slot = true;
break;
}

View file

@ -82,3 +82,21 @@ pub fn line_table(
}
println!("{}{}", line, rs);
}
// Split a string in half with respect of words
pub fn split_half(text: &str) -> (&str, &str) {
let mid = text.len() / 2;
for (i, j) in (mid..text.len()).enumerate() {
if text.as_bytes()[j] == b' ' {
return text.split_at(mid + i);
}
}
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)
}