forked from Anri/cal8tor
Add stuff to build the table
This commit is contained in:
parent
ab416848ef
commit
e4aa7c624c
2 changed files with 102 additions and 0 deletions
|
@ -33,3 +33,55 @@ pub struct Day {
|
|||
/// Ordered list of all the courses of the day
|
||||
pub courses: Vec<Option<Course>>,
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
|
50
src/utils.rs
50
src/utils.rs
|
@ -1,3 +1,5 @@
|
|||
use crate::timetable::models::{Position, TabChar};
|
||||
|
||||
/// Panic if an error happened
|
||||
pub fn check_errors(html: &String, loc: &str) {
|
||||
match html {
|
||||
|
@ -13,3 +15,51 @@ pub fn check_errors(html: &String, loc: &str) {
|
|||
fn err_code(code: i32) -> String {
|
||||
format!("HTTP Code : {}", code)
|
||||
}
|
||||
|
||||
/// Print a line for the table
|
||||
///
|
||||
/// `pos` defines what separator should be used and can be:
|
||||
/// - 0 -> top of the table
|
||||
/// - 1 -> middle of the table
|
||||
/// - 2 -> bottom of the table
|
||||
pub fn line_table(cell_length: usize, number_cell: usize, pos: Position) {
|
||||
let err_msg = "Unknown position";
|
||||
|
||||
// Left side
|
||||
let ls = match pos {
|
||||
Position::Top => TabChar::Jtl.val(),
|
||||
Position::Middle => TabChar::Jl.val(),
|
||||
Position::Bottom => TabChar::Jbl.val(),
|
||||
_ => panic!("{}", err_msg),
|
||||
};
|
||||
|
||||
// Middle
|
||||
let ms = match pos {
|
||||
Position::Top => TabChar::Jtb.val(),
|
||||
Position::Middle => TabChar::Jm.val(),
|
||||
Position::Bottom => TabChar::Jtt.val(),
|
||||
_ => panic!("{}", err_msg),
|
||||
};
|
||||
|
||||
// Right side
|
||||
let rs = match pos {
|
||||
Position::Top => TabChar::Jtr.val(),
|
||||
Position::Middle => TabChar::Jr.val(),
|
||||
Position::Bottom => TabChar::Jbr.val(),
|
||||
_ => panic!("{}", err_msg),
|
||||
};
|
||||
|
||||
let line = TabChar::Bh.val().to_string().repeat(cell_length);
|
||||
|
||||
// Print the line
|
||||
print!(
|
||||
"\n{}{}{}",
|
||||
ls,
|
||||
line,
|
||||
ms
|
||||
);
|
||||
for _ in 2..number_cell {
|
||||
print!("{}{}", line, ms);
|
||||
}
|
||||
println!("{}{}", line, rs);
|
||||
}
|
||||
|
|
Reference in a new issue