11 个版本 (4 个重大更新)
0.5.2 | 2019 年 10 月 21 日 |
---|---|
0.4.1 | 2019 年 8 月 2 日 |
0.4.0 | 2019 年 7 月 26 日 |
0.2.0 | 2019 年 2 月 22 日 |
#34 在 #crossterm
每月下载量 1,662
55KB
866 行
Crossterm Style
crossterm_style
包已被废弃,不再维护。GitHub 仓库将很快被存档。所有代码都将迁移到 crossterm
包。您可以在 将子包合并到 crossterm 包 的问题中了解更多信息。
此包允许您处理终端颜色和文本属性。它支持所有 UNIX 和 Windows 7 及以上版本的终端(并非所有终端都经过测试,有关更多信息,请参阅已测试终端)。
crossterm_style
是 crossterm 包的子包。您可以直接使用它,但强烈建议您启用 style
功能来使用 crossterm 包。
特性
- 跨平台
- 多线程(发送、同步)
- 详细的文档
- 依赖项少
- 样式化输出
- 前景色(16种基本颜色)
- 背景色(16种基本颜色)
- 256 (ANSI) 颜色支持(仅限 Windows 10 和 UNIX)
- RGB 颜色支持(仅限 Windows 10 和 UNIX)
- 文本属性,如粗体、斜体、下划线、删除线等。
入门指南
点击以显示 Cargo.toml。
[dependencies]
# All crossterm features are enabled by default.
crossterm = "0.11"
属性
use crossterm::{Colored, Color, Colorize, Styler, Attribute};
// pass any `Attribute` value to the formatting braces.
println!("{} Underlined {} No Underline", Attribute::Underlined, Attribute::NoUnderline);
// you could also call different attribute methods on a `&str` and keep on chaining if needed.
let styled_text = "Bold Underlined".bold().underlined();
println!("{}", styled_text);
// old-way but still usable
let styled_text = style("Bold Underlined").bold().underlined();
颜色
use crossterm::{Colored, Color, Colorize};
println!("{} Red foreground color", Colored::Fg(Color::Red));
println!("{} Blue background color", Colored::Bg(Color::Blue));
// you can also call different coloring methods on a `&str`.
let styled_text = "Bold Underlined".red().on_blue();
println!("{}", styled_text);
// old-way but still usable
let styled_text = style("Bold Underlined").with(Color::Red).on(Color::Blue);
RGB 颜色和 ANSI 值
use crossterm::{Colored, Color, Colorize};
// custom rgb value (Windows 10 and UNIX systems)
println!("{} some colored text", Colored::Fg(Color::Rgb {
r: 10,
g: 10,
b: 10
}));
// custom ansi color value (Windows 10 and UNIX systems)
println!("{} some colored text", Colored::Fg(Color::AnsiValue(10)));
其他资源
作者
- Timon Post - 项目负责人 & 创建者
许可证
本项目采用 MIT 许可证 - 有关详细信息,请参阅LICENSE 文件。
依赖项
~29–430KB