ratatui/examples/widget_ext.rs
Josh McKinney 0d54ca06f8
feat: add WidgetExt trait for debugging widgets
Importing the `WidgetExt` trait allows users to easily get a string
representation of a widget with ANSI escape sequences for the terminal.
This is useful for debugging and testing widgets.

```rust
use ratatui::{prelude::*, widgets::widget_ext::WidgetExt};

fn main() {
    let greeting = Text::from(vec![
        Line::styled("Hello", Color::Blue),
        Line::styled("World ", Color::Green),
    ]);
    println!("{}", greeting.to_ansi_string(5, 2));
}
```

Fixes: https://github.com/ratatui-org/ratatui/issues/1045
2024-04-25 19:20:45 -07:00

10 lines
259 B
Rust

use ratatui::{prelude::*, widgets::widget_ext::WidgetExt};
fn main() {
let greeting = Text::from(vec![
Line::styled("Hello", Color::Blue),
Line::styled("World ", Color::Green),
]);
println!("{}", greeting.to_ansi_string(5, 2));
}