Skip to content

Commit

Permalink
Example: ansi_crossterm
Browse files Browse the repository at this point in the history
  • Loading branch information
xairaven committed Sep 16, 2024
1 parent ca3faf7 commit 1f26796
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cursive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
25 changes: 25 additions & 0 deletions cursive/examples/ansi_crossterm.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 1f26796

Please sign in to comment.