This repository has been archived on 2024-05-23. You can view files and clone it, but cannot push or open issues or pull requests.
cal8tor/src/utils.rs

54 lines
1.6 KiB
Rust
Raw Normal View History

2022-08-23 13:22:56 +02:00
pub mod models;
2022-08-23 13:16:58 +02:00
2022-08-16 15:48:13 +02:00
/// Panic if an error happened
pub fn check_errors(html: &String, loc: &str) {
match html {
t if t.contains(&err_code(429)) => panic!(
"URL: {} • HTTP 429: Slow down - Rate limited (too many access attempts detected)",
loc
),
_ => (),
}
}
/// Create String error code
fn err_code(code: i32) -> String {
format!("HTTP Code : {}", code)
}
2022-08-23 13:16:58 +02:00
/// Print a line for the table
2022-08-23 13:42:16 +02:00
pub fn line_table(cell_length: usize, number_cell: usize, pos: models::Position, skip_with: std::collections::HashMap<usize, &str>) {
2022-08-23 13:16:58 +02:00
// Left side
let ls = match pos {
2022-08-23 13:22:56 +02:00
models::Position::Top => models::TabChar::Jtl.val(),
models::Position::Middle => models::TabChar::Jl.val(),
models::Position::Bottom => models::TabChar::Jbl.val(),
2022-08-23 13:16:58 +02:00
};
// Middle
let ms = match pos {
2022-08-23 13:22:56 +02:00
models::Position::Top => models::TabChar::Jtb.val(),
models::Position::Middle => models::TabChar::Jm.val(),
models::Position::Bottom => models::TabChar::Jtt.val(),
2022-08-23 13:16:58 +02:00
};
// Right side
let rs = match pos {
2022-08-23 13:22:56 +02:00
models::Position::Top => models::TabChar::Jtr.val(),
models::Position::Middle => models::TabChar::Jr.val(),
models::Position::Bottom => models::TabChar::Jbr.val(),
2022-08-23 13:16:58 +02:00
};
2022-08-23 13:22:56 +02:00
let line = models::TabChar::Bh.val().to_string().repeat(cell_length);
2022-08-23 13:16:58 +02:00
// Print the line
2022-08-23 13:22:56 +02:00
print!("\n{}{}{}", ls, line, ms);
2022-08-23 13:42:16 +02:00
for i in 0..number_cell - 2 {
match skip_with.get(&i) {
Some(text) => print!("{:^cell_length$}{}", text, ms),
None => print!("{}{}", line, ms),
}
2022-08-23 13:16:58 +02:00
}
println!("{}{}", line, rs);
}