1use std::{fs::File, io::{self, BufRead}, path::Path, thread, time::Duration};
2use crate::output::style::build;
3use crate::output::themes::current_theme;
4
5pub fn line(text: &str) {
7 println!("{}", text);
8}
9
10pub fn write(text: &str) {
12 print!("{}", text);
13}
14
15pub fn end() {
17 println!();
18}
19
20pub fn scroll(multiline: &[&str], delay_ms: u64) {
22 for text_line in multiline {
23 line(text_line);
24 if delay_ms > 0 {
25 std::thread::sleep(std::time::Duration::from_millis(delay_ms));
26 }
27 }
28}
29
30pub fn file(path: &str, delay_ms: u64) {
32 if let Ok(lines) = read_lines(path) {
33 for text_line in lines.flatten() {
34 line(&text_line);
35 if delay_ms > 0 {
36 thread::sleep(Duration::from_millis(delay_ms));
37 }
38 }
39 } else {
40 error("Failed to open file");
41 }
42}
43
44fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
46where P: AsRef<Path> {
47 let file = File::open(filename)?;
48 Ok(io::BufReader::new(file).lines())
49}
50
51pub fn debug(msg: &str) {
54 let theme = current_theme();
55 let styled = build()
56 .part("DEBUG:").color(theme.get_log_color("debug")).space()
57 .part(msg).get();
58 line(&styled);
59}
60
61pub fn info(msg: &str) {
62 let theme = current_theme();
63 let styled = build()
64 .part("INFO:").color(theme.get_log_color("info")).bold().space()
65 .part(msg).get();
66 line(&styled);
67}
68
69pub fn warn(msg: &str) {
70 let theme = current_theme();
71 let styled = build()
72 .part("WARNING:").color(theme.get_log_color("warn")).bold().space()
73 .part(msg).get();
74 line(&styled);
75}
76
77pub fn error(msg: &str) {
78 let theme = current_theme();
79 let styled = build()
80 .part("ERROR:").color(theme.get_log_color("error")).bold().space()
81 .part(msg).get();
82 line(&styled);
83}
84
85pub fn success(msg: &str) {
86 let theme = current_theme();
87 let styled = build()
88 .part("SUCCESS:").color(theme.get_log_color("success")).bold().space()
89 .part(msg).get();
90 line(&styled);
91}
92
93pub fn status(msg: &str) {
94 let theme = current_theme();
95 let styled = build()
96 .part("STATUS ").color(theme.get_log_color("info")).bold().space()
97 .part(msg).get();
98 line(&styled);
99}
100
101pub fn deprecated(msg: &str) {
102 let theme = current_theme();
103 let styled = build()
104 .part("DEPRECATED:").color(theme.get_log_color("warn")).bold().space()
105 .part(msg).get();
106 line(&styled);
107}
108
109pub fn unknown(msg: &str) {
110 let theme = current_theme();
111 let styled = build()
112 .part("WARNING:").color(theme.get_log_color("warn")).bold().space()
113 .part(msg).get();
114 line(&styled);
115}