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
extern crate lazy_static;
mod codes;
mod custom;
mod styling;
mod templating;
pub use codes::CODES;
pub use custom::{add_style, delete_styles, resolve_styles, CustomStyleError};
pub use styling::ColorError;
pub use templating::{clean_template, colorize_template};
pub fn colorize(content: &str, styles: &[&str]) -> String {
let mut header = String::new();
let mut footer = String::new();
for style in styles {
let tokens: Vec<&str> = style.split(" ").collect();
for resolved in custom::resolve_styles(&tokens) {
let (open, close) = styling::style_to_ansi(&resolved);
if open != "" && close != "" {
header.push_str(open.as_str());
footer.insert_str(0, close.as_str());
}
}
}
format!("{}{}{}", header, content, footer)
}