Skip to content

Instantly share code, notes, and snippets.

@jcbritobr
Created October 11, 2020 17:18
Show Gist options
  • Save jcbritobr/08f934b331fb4ab03ecb501bd1fbd394 to your computer and use it in GitHub Desktop.
Save jcbritobr/08f934b331fb4ab03ecb501bd1fbd394 to your computer and use it in GitHub Desktop.
Cursive sample with generation and destruction of dialogs.
[package]
name = "cursive_test_windows"
version = "0.1.0"
authors = ["unknown <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies.cursive]
version = "0.15.0"
default-features = false
features = ["pancurses-backend"]
use cursive::{self, Cursive, views::Dialog};
fn main() {
let mut siv = cursive::default();
let dialog =
Dialog::text("This is a survey\nPress <Next> when you're ready.").title("Important Survey").button("Next", show_next);
siv.add_layer(dialog);
siv.run();
}
fn show_next(s: &mut Cursive) {
s.pop_layer();
let dialog = Dialog::text("Did you do the thing")
.title("Question 1")
.button("yes", |s| show_answer(s, "I knew it! Well done!"))
.button("No!", |s|show_answer(s, "I knew you coldn't be trusted!"))
.button("Uh?", |s| s.add_layer(Dialog::info("Try again!!")));
s.add_layer(dialog);
}
fn show_answer(s: &mut Cursive, msg: &str) {
s.pop_layer();
let dialog = Dialog::text(msg).title("Results").button("Finnsh", |s| s.quit());
s.add_layer(dialog);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment