summaryrefslogtreecommitdiff
path: root/src/drawing.rs
blob: f65ca8f28b6741a75b63531a0d54081f66067103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use console::Term;
use colored::Colorize;
use std::io::{self, Write};

pub enum Category<'a> {
    Title(&'a str),
    Line(&'a str),
    Wrong(&'a str),
    Menu,
    Clear,
}

pub fn ui(is: Category) -> char {
    let term = Term::stdout;
    let (_, cols) = term().size();

    match is {
        Category::Title(s) => drawing_title(&s, cols),
        Category::Line(s) => drawing_line(&s),
        Category::Wrong(s) => drawing_error(&s, cols),
        Category::Menu => return drawing_menu(),
        Category::Clear => clear_screen(),
    }

    // return randomly if pattern is not menu
    return 'a'
}

fn drawing_menu() -> char {
    let term = Term::stdout;

    ui(Category::Title("MOZE Analyzer"));

    println!("a. print summary by project\t\tb. print summary by time");
    println!("q. quit");
    print!("\nEnter your option: ");
    io::stdout().flush().unwrap();
    let option = term().read_char().unwrap();

    println!("{}\n", String::from(option).blue());

    option
}

fn drawing_title(s: &str, cols: u16) {
    println!("");

    for _ in 0..cols {
        print!("-");
    }
    println!("");
    for _ in 0..((cols - s.len() as u16) / 2) {
        print!(" ");
    }

    println!("{}", s.green());
    for _ in 0..cols {
        print!("-");
    }
    println!("");
}

fn drawing_line(s: &str) {
    println!("{s}");
}

fn drawing_error(s: &str, cols: u16) {
    for _ in 0..((cols - s.len() as u16) / 2) {
        print!(" ");
    }
    println!("{}",s.red());
}

fn clear_screen() {
    let term = Term::stdout;
    let _ = term().clear_screen();
}