Crates.io | color-string |
lib.rs | color-string |
version | 0.1.6 |
source | src |
created_at | 2023-11-17 08:52:14.752644 |
updated_at | 2023-12-13 19:15:32.740323 |
description | 简单的彩色字符串工具 |
homepage | |
repository | https://github.com/mllcms/color-string |
max_upload_size | |
id | 1038836 |
size | 15,824 |
彩色字符串
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());
}