advance/advance.rs
1use formatx::Template;
2
3fn main() {
4 let mut template = "{percentage color=true:.2} => {percentage color=false:.0}%"
5 .parse::<Template>()
6 .unwrap();
7
8 template.replace_with_callback("percentage", 99.9999, |fmtval, placeholder| {
9 if let Some(color) = placeholder.attr("color") {
10 if color == "true" {
11 return "\x1b[31m".to_owned() + &fmtval + "\x1b[0m";
12 }
13 }
14
15 fmtval
16 });
17
18 println!("{}", template.text().unwrap());
19}