make the table more readable
This commit is contained in:
parent
2f42d4de91
commit
cbc17ba85d
2 changed files with 36 additions and 4 deletions
|
@ -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 course.size > 1 {
|
||||
// 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);
|
||||
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
|
||||
// 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;
|
||||
}
|
||||
|
|
18
src/utils.rs
18
src/utils.rs
|
@ -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)
|
||||
}
|
||||
|
|
Reference in a new issue