6 个版本
使用旧的 Rust 2015
0.1.5 | 2018年10月23日 |
---|---|
0.1.4 | 2018年8月10日 |
0.1.2 | 2018年7月28日 |
在 开发工具 中排名第 1814
每月下载量 48 次
31KB
624 行代码(不包括注释)
cluColor
格式化记录颜色输出的方法。
格式化记录的简单方法
#[macro_use]
extern crate clucolor;
let str_colored = color!(blue, "test");
println!("{}", str_colored);
let str_colored = color!(blue, bold, "test");
println!("{}", str_colored);
let str_colored = color!(bright_red, bold, "test");
println!("{}", str_colored);
使用颜色类型生成字符串
#[macro_use]
extern crate clucolor;
use clucolor::colors::cluColor;
use clucolor::colors::BrightRed;
let string = BrightRed::string_fmt( format_args!("[{:?}] {}", TEST, str) );
let string = BrightRed::stringn( "color str!" );
在 Write 特性中记录宏
#[macro_use]
extern crate clucolor;
use clucolor::colors::Blue;
use clucolor::colors::BrightBlue;
writen_color!(&mut ::std::io::stdout(), BrightBlue, "OutValueTest {}", 123);
writen_color!(&mut ::std::io::stdout(), BrightBlue, "OutValueTest2 {}", 12345);
writen_color!(&mut File::open("color_file.txt"), BrightBlue, "Color Str:)", 12345);
使用颜色类型记录
#[macro_use]
extern crate clucolor;
use clucolor::colors::Blue;
use clucolor::colors::BrightBlue;
let mut vec: Vec<u8> = Vec::new(); // For Vec implemented Write!!
let _e = BrightBlue::write_str(&mut vec, "color str!" );
let _e = vec.write(b"TestValue"); // For Vec implemented Write!!
//Also this value will remain without color formatting.
let _e = BrightBlue::writen_str(&mut vec, "end str.." );
let _e = BrightRed::writen(&mut vec, b"end value.." );
使用移动颜色参数
#[macro_use]
extern crate clucolor;
use clucolor::colors::BrightBlue;
#[derive(Debug, Default)]
pub struct Items(usize, usize);
impl Items {
#[inline]
pub fn count(&self) -> usize {
self.0 + self.1
}
}
let mut item = Items::default();
for a in 0..15 {
BrightGreen::with_color_fmt(format_args!("NUM #{}", a), |fmt_num| {
BrightBlue::with_color_fmt(format_args!("ITEM #{:?}", item), |fmt_item| {
BrightRed::with_color_fmt(format_args!("ALL_COUNT {}", item.count()), |fmt_count| {
println!("{}, {}; {};", fmt_num, fmt_item, fmt_count);
});
});
});
item.0 += 1;
item.1 += 2;
}
使用 ColorWriter
#[macro_use]
extern crate clucolor;
use clucolor::colors::Blue;
let writer = Blue::writer();
let stdout = ::std::io::stdout();
let mut lock_stdio = stdout.lock();
writer.writen(&mut lock_stdio, b"TestWriten").unwrap();
All other functions are implemented in color mod with the help of cluColor!
许可协议
版权所有 © 2018 #UlinProject Денис Котляров
根据 Apache License,版本 2.0 许可