Struct tui_markup::generator::tui::TuiTextGenerator
source · [−]pub struct TuiTextGenerator<P = NoopCustomTagParser<Style>> { /* private fields */ }Available on crate feature
tui only.Expand description
Generator for tui crate’s Text type.
See docs/tui-tags.ebnf for supported tags.
Example
use tui_markup::{compile, generator::TuiTextGenerator};
assert_eq!(
compile::<TuiTextGenerator>("I have a <green green text>"),
Ok(Text { lines: vec![Spans(vec![
Span::raw("I have a "),
Span::styled("green text", Style::default().fg(Color::Green)),
])] }),
);
assert_eq!(
compile::<TuiTextGenerator>("I can set <bg:blue background>"),
Ok(Text { lines: vec![Spans(vec![
Span::raw("I can set "),
Span::styled("background", Style::default().bg(Color::Blue)),
])] }),
);
assert_eq!(
compile::<TuiTextGenerator>("I can add <b bold>, <d dim>, <i italic> modifiers"),
Ok(Text { lines: vec![Spans(vec![
Span::raw("I can add "),
Span::styled("bold", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(", "),
Span::styled("dim", Style::default().add_modifier(Modifier::DIM)),
Span::raw(", "),
Span::styled("italic", Style::default().add_modifier(Modifier::ITALIC)),
Span::raw(" modifiers"),
])] }),
);
assert_eq!(
compile::<TuiTextGenerator>("I can <bg:blue combine <green them <b <i all>>>>"),
Ok(Text { lines: vec![Spans(vec![
Span::raw("I can "),
Span::styled("combine ", Style::default().bg(Color::Blue)),
Span::styled("them ", Style::default().bg(Color::Blue).fg(Color::Green)),
Span::styled("all", Style::default()
.bg(Color::Blue).fg(Color::Green).add_modifier(Modifier::BOLD | Modifier::ITALIC)),
])] }),
);
assert_eq!(
compile::<TuiTextGenerator>("I can use <bg:66ccff custom color>"),
Ok(Text { lines: vec![Spans(vec![
Span::raw("I can use "),
Span::styled("custom color", Style::default().bg(Color::Rgb(0x66, 0xcc, 0xff))),
])] }),
);
assert_eq!(
compile::<TuiTextGenerator>("I can set <bg:blue,green,b,i many style> in one tag"),
Ok(Text { lines: vec![Spans(vec![
Span::raw("I can set "),
Span::styled("many style", Style::default()
.bg(Color::Blue).fg(Color::Green).add_modifier(Modifier::BOLD | Modifier::ITALIC)),
Span::raw(" in one tag"),
])] }),
);With custom tags
use tui_markup::{compile_with, generator::TuiTextGenerator};
let gen = TuiTextGenerator::new(|tag: &str| match tag {
"keyboard" => Some(Style::default().bg(Color::White).fg(Color::Green).add_modifier(Modifier::BOLD)),
_ => None,
});
assert_eq!(
compile_with("Press <keyboard W> to move up", gen),
Ok(Text { lines: vec![Spans(vec![
Span::raw("Press "),
Span::styled("W", Style::default().bg(Color::White).fg(Color::Green).add_modifier(Modifier::BOLD)),
Span::raw(" to move up"),
])] }),
);Show output
Use any widget of tui crate that supports it’s Text type, for example: tui::widgets::Paragraph.
Implementations
sourceimpl<P> TuiTextGenerator<P>
impl<P> TuiTextGenerator<P>
Trait Implementations
sourceimpl<P: Debug> Debug for TuiTextGenerator<P>
impl<P: Debug> Debug for TuiTextGenerator<P>
sourceimpl<P> Default for TuiTextGenerator<P>
impl<P> Default for TuiTextGenerator<P>
sourceimpl<'a, P> Generator<'a> for TuiTextGenerator<P> where
P: CustomTagParser<Output = Style>,
impl<'a, P> Generator<'a> for TuiTextGenerator<P> where
P: CustomTagParser<Output = Style>,
type Convertor = TuiTagConvertor<P>
type Convertor = TuiTagConvertor<P>
Tag convertor type.
type Err = GeneratorInfallible
type Err = GeneratorInfallible
Error type. Read more
Auto Trait Implementations
impl<P> RefUnwindSafe for TuiTextGenerator<P> where
P: RefUnwindSafe,
impl<P> Send for TuiTextGenerator<P> where
P: Send,
impl<P> Sync for TuiTextGenerator<P> where
P: Sync,
impl<P> Unpin for TuiTextGenerator<P> where
P: Unpin,
impl<P> UnwindSafe for TuiTextGenerator<P> where
P: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more