feat: add __term/tui-markup-demo/

This commit is contained in:
2025-07-12 18:24:46 +08:00
parent 73d58350c2
commit bd9ea78e53
4 changed files with 123 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
use ansi_term::{ANSIStrings, Color, Style};
use tui_markup::generator::ANSIStringsGenerator;
use tui_markup::{compile, compile_with};
fn main() {
// Parse markup into some final result for showing
let result = compile::<ANSIStringsGenerator>("You got a <yellow Coin>").unwrap();
// Show it
println!("{}", ANSIStrings(&result));
// With custom tag
let generator = ANSIStringsGenerator::new(|tag: &str| match tag {
"keyboard" => Some(Style::default().fg(Color::Blue).on(Color::Black).bold()),
"bold" => Some(Style::default().bold()),
"under" => Some(Style::default().underline()),
_ => None,
});
let result = compile_with("Press <keyboard Space> to <bold <under jump>>", generator).unwrap();
println!("{}", ANSIStrings(&result));
}