File: advance.rs

package info (click to toggle)
rust-formatx 0.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 180 kB
  • sloc: makefile: 4
file content (19 lines) | stat: -rw-r--r-- 525 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use formatx::Template;

fn main() {
    let mut template = "{percentage color=true:.2} => {percentage color=false:.0}%"
        .parse::<Template>()
        .unwrap();

    template.replace_with_callback("percentage", 99.9999, |fmtval, placeholder| {
        if let Some(color) = placeholder.attr("color") {
            if color == "true" {
                return "\x1b[31m".to_owned() + &fmtval + "\x1b[0m";
            }
        }

        fmtval
    });

    println!("{}", template.text().unwrap());
}