1 个不稳定版本
0.1.0 | 2020年8月13日 |
---|
#2565 in Rust模式
8KB
sgr_const!
一个宏,用于生成终端应用程序中彩色输出的SGR(设置图形渲染)控制序列。
[dependencies]
sgr-const = "0.1"
示例
sgr_const::sgr_const! {
STYLE_CYAN = Bold | CyanFg;
STYLE_NONE = Reset;
}
println!("{}{}{}", STYLE_CYAN, "This text will be cyan if your terminal supports it!", STYLE_NONE);
许可证
本项目采用Mozilla公共许可证第2版许可。有关更多信息,请参阅LICENSE。
lib.rs
:
一个宏,用于生成SGR(设置图形渲染)控制序列,用于兼容ECMA-48的终端。
示例
通用语法是
[visibity] <name> = <attribute> [| attributes...];
您可以一次指定多个常量,并为每个常量添加属性或文档注释
sgr_const::sgr_const! {
/// Error styling. Should be flashy.
STYLE_ERROR = Bold | BlackFg | RedBg;
STYLE_WARN = Bold | YellowFg;
STYLE_INFO = Bold | CyanFg;
STYLE_DEBUG = MagentaFg;
#[allow(unused)]
STYLE_TRACE = GreenFg;
STYLE_NONE = Reset;
}
assert_eq!(STYLE_ERROR, "\x1b[1;30;41m");
assert_eq!(STYLE_WARN, "\x1b[1;33m");
assert_eq!(STYLE_INFO, "\x1b[1;36m");
assert_eq!(STYLE_DEBUG, "\x1b[35m");
assert_eq!(STYLE_TRACE, "\x1b[32m");
assert_eq!(STYLE_NONE, "\x1b[0m");