#color #string #terminal #term

bin+lib color-string

简单的彩色字符串工具

5 releases

0.1.6 Dec 13, 2023
0.1.5 Dec 13, 2023
0.1.2 Nov 17, 2023

#22 in #term

Download history 15/week @ 2024-02-26 11/week @ 2024-03-11 8/week @ 2024-03-18 3/week @ 2024-03-25 83/week @ 2024-04-01

105 downloads per month
Used in mll-axum-utils

MIT license

16KB
314 lines

color-string

彩色字符串

use color_string::Font::*;
use color_string::{cs, fonts, pcs, wcs, wf, Colored, FontTool};

fn main() {
    let fonts = fonts!(Red, Bold);

    let mut s1 = String::new();
    wcs!(&mut s1, fonts => "Hello World!");

    let mut s2 = String::new();
    wcs!(&mut s2, fonts; "{} {}","Hello","World!");

    let s3 = "Hello World!".fonts(fonts.clone());
    let s4 = cs!(fonts => "Hello World!");
    let s5 = cs!(Red,Bold; "{} {}", "Hello","World!");
    let s6 = cs!(Red,Bold => "Hello ","World!");
    let s7 = format!("{}Hello World!{}", fonts, Reset);

    let mut ss = String::new();
    wf!(&mut ss, Red, Bold);
    ss.push_str("Hello ");
    ss.push_str("World!");
    ss.reset();

    assert_eq!("\u{1b}[31;1mHello World!\u{1b}[0m", ss,);
    for s in [s1, s2, s3, s4, s5, s6, s7] {
        assert_eq!(ss, s)
    }

    // Print server start
    pcs!(Green => ""; RBold => "Local: "; RCyan => "http://127.0.0.1:", 5173.bold());
}

No runtime deps