summaryrefslogtreecommitdiff
path: root/src/drawing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/drawing.rs')
-rw-r--r--src/drawing.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/drawing.rs b/src/drawing.rs
new file mode 100644
index 0000000..f65ca8f
--- /dev/null
+++ b/src/drawing.rs
@@ -0,0 +1,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();
+}