4 个版本
0.2.2 | 2024 年 2 月 7 日 |
---|---|
0.2.1 | 2024 年 2 月 7 日 |
0.2.0 | 2024 年 2 月 7 日 |
0.1.0 | 2024 年 1 月 12 日 |
379 在 文本处理 中
83 每月下载次数
在 2 个 Crates 中使用 (logfather)
27KB
229 行
装饰器
简单的 Rust 通用字符和风格库,旨在通过各种文本样式和 UTF-8 字符增强控制台输出。
特性
- 易用性:使用单个宏调用或函数应用多个文本样式。
- 安全性:宏编译时检查防止使用无效的样式名称。
- 灵活的样式:支持
style!()
宏。- 使用
ANSI
代码生成用于控制台输出的样式字符串。 - 着色文本的前景和背景。
- 以任何组合应用 粗体、下划线(Markdown 不支持下划线) 和 斜体 文本。
- 使用
- RGB 颜色支持:使用 RGB 值应用自定义文本颜色。
- 全面字符集:提供各种 UTF-8 字符的
Utf8
枚举。- 计划随着时间的推移完成字符列表
- 字符列表来源: https://www.fileformat.info/info/charset/UTF-8/list.htm
- 实现
Display
并具有函数.repeat(n)
,其中n
是usize
入门
要开始使用装饰器,将以下内容添加到您的 Cargo.toml
[dependencies]
dekor = "0.2.1"
- 最低支持的 Rust 版本:
1.56.1
用法
基本文本样式
use dekor::*;
fn main() {
let decorated_text_macro = style!(Bold, Underline, FGBlue => "This is decorated text");
println!("{}", decorated_text_macro);
// Output will be blue text that is underlined and bolded.
let styles = [Style::Bold, Style::Underline, Style::FGBlue];
let decorated_text_function = style(styles, "This is decorated text");
assert_eq!(decorated_text_macro, decorated_text_function);
}
使用 RGB 颜色
use dekor::*;
fn main() {
// Applying RGB colors for foreground and background
let styles = vec![(Style::FGRGB, 255, 100, 50), (Style::BGRGB, 0, 0, 255)];
let rgb_text_function = styler(styles, "RGB Styled Text");
println!("{}", rgb_text_function);
// The text will have a custom foreground and background color.
let rgb_text_macro = style!((FGRGB, 255, 100, 50), (BGRGB, 0, 0, 255) => "RGB Styled Text");
assert_eq!(rgb_text_function, rgb_text_macro);
}
处理 UTF-8 字符
use dekor::*;
fn main() {
let decorated_text = style!(Bold, Underline, FGBlue => "This is decorated text");
let pipes = format!("{}\n{}{}\n{}{}",
Utf8::VPipeSlim,
Utf8::JointPipeSlim, Utf8::HPipeSlim,
Utf8::NodePipeSlim, Utf8::HPipeSlim,
);
// Output:
// This is decorated text <-- Will be blue text that is underlined and bolded
// │
// ├— <-- Note: Markdown will display the horizontal line slimmer than it is
// └—
println!("{}\n{}", decorated_text, pipes);
}
示例输出
- 字符:
Utf8::VPipeSlim
、Utf8::JointPipeSlim
、Utf8::NodePipeCurved
、Utf8::HPipeSlim
和Utf8::ModLetterDownArrowhead
- 样式:
FGBlue
、Bold
use dekor::*;
fn main() {
let folder = style!(FGBlue, Bold => "Folder"); // Style the folder
let down_arrow = style!(Bold, FGGreen => Utf8::ModLetterDownArrowhead); // Style the open/close indicator
let hpipe = Utf8::HPipeSlim.repeat(2); // `Utf8` implements `Display` and `.repeat()`
println!("{}\n{}{}[{}]{}",
Utf8::VPipeSlim, Utf8::JointPipeSlim, hpipe, down_arrow, folder
);
}
目标
- 创建一个宏,允许进行文本样式
- 允许处理RGB和十六进制输入
- 提供宏的功能实现,以实现更稳健的方法
- 导入文件树显示所需的字符
- 导入剩余的UTF-8字符
- 考虑使用转义键来显示这些字符,因为其中一些显示不正确
许可证
本项目受MIT许可证的许可 - 有关详细信息,请参阅LICENSE文件。
贡献
._. 你为什么要这样做?
- 帮助将所有字符导入字符库将非常有帮助,只需分支并提交拉取请求。尽可能使用提供的链接和它们的命名方案来保持一致性。