forked from Anri/cal8tor
move enum to other file
This commit is contained in:
parent
e4aa7c624c
commit
5bc1ddb64d
3 changed files with 64 additions and 70 deletions
|
@ -33,55 +33,3 @@ pub struct Day {
|
||||||
/// Ordered list of all the courses of the day
|
/// Ordered list of all the courses of the day
|
||||||
pub courses: Vec<Option<Course>>,
|
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
|
|
||||||
}
|
|
||||||
|
|
31
src/utils.rs
31
src/utils.rs
|
@ -1,4 +1,4 @@
|
||||||
use crate::timetable::models::{Position, TabChar};
|
pub mod models;
|
||||||
|
|
||||||
/// Panic if an error happened
|
/// Panic if an error happened
|
||||||
pub fn check_errors(html: &String, loc: &str) {
|
pub fn check_errors(html: &String, loc: &str) {
|
||||||
|
@ -22,42 +22,37 @@ fn err_code(code: i32) -> String {
|
||||||
/// - 0 -> top of the table
|
/// - 0 -> top of the table
|
||||||
/// - 1 -> middle of the table
|
/// - 1 -> middle of the table
|
||||||
/// - 2 -> bottom of the table
|
/// - 2 -> bottom of the table
|
||||||
pub fn line_table(cell_length: usize, number_cell: usize, pos: Position) {
|
pub fn line_table(cell_length: usize, number_cell: usize, pos: models::Position) {
|
||||||
let err_msg = "Unknown position";
|
let err_msg = "Unknown position";
|
||||||
|
|
||||||
// Left side
|
// Left side
|
||||||
let ls = match pos {
|
let ls = match pos {
|
||||||
Position::Top => TabChar::Jtl.val(),
|
models::Position::Top => models::TabChar::Jtl.val(),
|
||||||
Position::Middle => TabChar::Jl.val(),
|
models::Position::Middle => models::TabChar::Jl.val(),
|
||||||
Position::Bottom => TabChar::Jbl.val(),
|
models::Position::Bottom => models::TabChar::Jbl.val(),
|
||||||
_ => panic!("{}", err_msg),
|
_ => panic!("{}", err_msg),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Middle
|
// Middle
|
||||||
let ms = match pos {
|
let ms = match pos {
|
||||||
Position::Top => TabChar::Jtb.val(),
|
models::Position::Top => models::TabChar::Jtb.val(),
|
||||||
Position::Middle => TabChar::Jm.val(),
|
models::Position::Middle => models::TabChar::Jm.val(),
|
||||||
Position::Bottom => TabChar::Jtt.val(),
|
models::Position::Bottom => models::TabChar::Jtt.val(),
|
||||||
_ => panic!("{}", err_msg),
|
_ => panic!("{}", err_msg),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Right side
|
// Right side
|
||||||
let rs = match pos {
|
let rs = match pos {
|
||||||
Position::Top => TabChar::Jtr.val(),
|
models::Position::Top => models::TabChar::Jtr.val(),
|
||||||
Position::Middle => TabChar::Jr.val(),
|
models::Position::Middle => models::TabChar::Jr.val(),
|
||||||
Position::Bottom => TabChar::Jbr.val(),
|
models::Position::Bottom => models::TabChar::Jbr.val(),
|
||||||
_ => panic!("{}", err_msg),
|
_ => panic!("{}", err_msg),
|
||||||
};
|
};
|
||||||
|
|
||||||
let line = TabChar::Bh.val().to_string().repeat(cell_length);
|
let line = models::TabChar::Bh.val().to_string().repeat(cell_length);
|
||||||
|
|
||||||
// Print the line
|
// Print the line
|
||||||
print!(
|
print!("\n{}{}{}", ls, line, ms);
|
||||||
"\n{}{}{}",
|
|
||||||
ls,
|
|
||||||
line,
|
|
||||||
ms
|
|
||||||
);
|
|
||||||
for _ in 2..number_cell {
|
for _ in 2..number_cell {
|
||||||
print!("{}{}", line, ms);
|
print!("{}{}", line, ms);
|
||||||
}
|
}
|
||||||
|
|
51
src/utils/models.rs
Normal file
51
src/utils/models.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/// 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
|
||||||
|
}
|
Reference in a new issue