1use crate::output::style::build;
2use crate::output::themes::current_theme;
3use std::{
4 fs::File,
5 io::{self, BufRead},
6 path::Path,
7 thread,
8 time::Duration,
9};
10
11pub fn line(text: &str) {
13 println!("{text}");
14}
15
16pub fn write(text: &str) {
18 print!("{text}");
19}
20
21pub fn newline() {
23 println!();
24}
25
26pub fn end() {
28 println!();
29}
30
31pub fn scroll(multiline: &[&str], delay_ms: u64) {
33 for text_line in multiline {
34 line(text_line);
35 if delay_ms > 0 {
36 std::thread::sleep(std::time::Duration::from_millis(delay_ms));
37 }
38 }
39}
40
41pub fn file(path: &str, delay_ms: u64) {
43 if let Ok(lines) = read_lines(path) {
44 for text_line in lines.map_while(Result::ok) {
45 line(&text_line);
46 if delay_ms > 0 {
47 thread::sleep(Duration::from_millis(delay_ms));
48 }
49 }
50 } else {
51 error("Failed to open file");
52 }
53}
54
55fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
57where
58 P: AsRef<Path>,
59{
60 let file = File::open(filename)?;
61 Ok(io::BufReader::new(file).lines())
62}
63
64pub fn debug(msg: &str) {
67 let theme = current_theme();
68 let styled = build()
69 .part("Debug:")
70 .color(theme.get_log_color("debug"))
71 .space()
72 .part(msg)
73 .get();
74 line(&styled);
75}
76
77pub fn info(msg: &str) {
78 let theme = current_theme();
79 let styled = build()
80 .part("Info:")
81 .color(theme.get_log_color("info"))
82 .bold()
83 .space()
84 .part(msg)
85 .get();
86 line(&styled);
87}
88
89pub fn warn(msg: &str) {
90 let theme = current_theme();
91 let styled = build()
92 .part("Warning:")
93 .color(theme.get_log_color("warn"))
94 .bold()
95 .space()
96 .part(msg)
97 .get();
98 line(&styled);
99}
100
101pub fn error(msg: &str) {
102 let theme = current_theme();
103 let styled = build()
104 .part("Error:")
105 .color(theme.get_log_color("error"))
106 .bold()
107 .space()
108 .part(msg)
109 .get();
110 line(&styled);
111}
112
113pub fn success(msg: &str) {
114 let theme = current_theme();
115 let styled = build()
116 .part("Success:")
117 .color(theme.get_log_color("success"))
118 .bold()
119 .space()
120 .part(msg)
121 .get();
122 line(&styled);
123}
124
125pub fn status(msg: &str) {
126 let theme = current_theme();
127 let styled = build()
128 .part("Status:")
129 .color(theme.get_log_color("status"))
130 .bold()
131 .space()
132 .part(msg)
133 .get();
134 line(&styled);
135}
136
137pub fn deprecated(msg: &str) {
138 let theme = current_theme();
139 let styled = build()
140 .part("Deprecated:")
141 .color(theme.get_log_color("notice"))
142 .bold()
143 .space()
144 .part(msg)
145 .get();
146 line(&styled);
147}
148
149pub fn unknown(msg: &str) {
150 let theme = current_theme();
151 let styled = build()
152 .part("Unknown Command:")
153 .color(theme.get_log_color("notice"))
154 .bold()
155 .space()
156 .part(msg)
157 .get();
158 line(&styled);
159}