From 1f267964f9bac15474eff51f1ae1ef10081fbc75 Mon Sep 17 00:00:00 2001 From: xairaven Date: Mon, 16 Sep 2024 23:59:39 +0300 Subject: [PATCH] Example: ansi_crossterm --- cursive/Cargo.toml | 4 ++++ cursive/examples/ansi_crossterm.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 cursive/examples/ansi_crossterm.rs diff --git a/cursive/Cargo.toml b/cursive/Cargo.toml index b5beb02f..b4947905 100644 --- a/cursive/Cargo.toml +++ b/cursive/Cargo.toml @@ -83,6 +83,10 @@ required-features = ["toml"] name = "ansi" required-features = ["ansi"] +[[example]] +name = "ansi_crossterm" +required-features = ["ansi", "crossterm-backend"] + [[example]] name = "builder" required-features = ["builder"] diff --git a/cursive/examples/ansi_crossterm.rs b/cursive/examples/ansi_crossterm.rs new file mode 100644 index 00000000..45d40360 --- /dev/null +++ b/cursive/examples/ansi_crossterm.rs @@ -0,0 +1,25 @@ +use crossterm::style::Stylize; +use cursive_core::views::{Dialog, LinearLayout, TextView}; + +fn main() { + // Using the crossterm function for text styling and casting it to a string. + let crossterm_colored = "Crossterm colored text.".red().to_string(); + + // Using this same function with another text, but parsing it as ANSI-decorated content. + let cursive_colored = cursive::utils::markup::ansi::parse( + "Cursive colored text (using Crossterm + ANSI)".red().to_string(), + ); + + // Minimal application for text output + let mut siv = cursive::default(); + siv.add_layer( + Dialog::new() + .content( + LinearLayout::vertical() + .child(TextView::new(crossterm_colored)) + .child(TextView::new(cursive_colored)), + ) + .button("Quit!", |s| s.quit()), + ); + siv.run(); +} \ No newline at end of file