cursive/examples/lorem.rs
Alexandre Bury db39069260 Fix focus for stack and text views.
And updated Lorem example with a Quit button under the scrollable text.
2015-05-30 21:54:06 -07:00

32 lines
915 B
Rust

extern crate cursive;
use cursive::Cursive;
use cursive::view::{TextView,Dialog};
use std::fs::File;
use std::io::Read;
fn main() {
// Read some long text from a file.
let mut file = File::open("assets/lorem.txt").unwrap();
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
let mut siv = Cursive::new();
// We can quit by pressing q
siv.add_global_callback('q', |s| s.quit());
// The text is too long to fit on a line, so the view will wrap lines,
// and will adapt to the terminal size.
siv.add_layer(Dialog::new(TextView::new(&content))
.button("Quit", |s| s.quit()));
// Show a popup on top of the view.
siv.add_layer(Dialog::new(TextView::new("Try resizing the terminal!\n(Press 'q' to quit when you're done.)"))
.padding((0,0,0,0))
.dismiss_button("Ok"));
siv.run();
}