#markup-language #ansi #markup #ansi-term #text #terminal #color

tui-markup-ansi-macro

一个用于从标记语言生成样式化ANSI转义序列的宏

1 个不稳定版本

0.1.0 2022年8月23日

#78 in #markup-language

BSD-3-Clause-Clear

10KB
109

tui markup ansi macro

crates.io changelog docs.rs deps state

此库提供了一个宏,用于使用标记语言生成终端样式文本的ANSI转义序列格式。

此宏在编译时编译源代码,因此没有运行时开销。

示例

use tui_markup_ansi_macro::ansi;

let generated = ansi!("Press <blue Space> to <cyan Jump> over the <bg:yellow,i fox>");
let hardcode = "Press \u{001b}[34mSpace\u{001b}[0m to \u{001b}[36mJump\u{001b}[0m over the \u{001b}[3;43mfox\u{001b}[0m";
// Those two are equivalent.
assert_eq!(generated, hardcode);

// Use custom tag
let generated = ansi!(
    "Press <keyboard Space> to <action Jump> over the <enemy fox>", 
    "keyboard" => "blue",
    "action" => "cyan",
    "enemy" => "bg:yellow,i",
);
assert_eq!(generated, hardcode);

println!("{}", generated);

输出

example-output

这里使用的标记语言是我的tui markup 语言,有关完整语法支持的样式标签,请参阅其文档。

许可证

BSD-3-Clause-Clear,请参阅许可证

依赖项

~1.3–1.8MB
~30K SLoC