cursive/examples/lorem.rs

33 lines
1007 B
Rust
Raw Permalink Normal View History

extern crate cursive;
use cursive::Cursive;
2015-06-03 02:36:22 +00:00
use cursive::align::HAlign;
2016-06-26 00:10:18 +00:00
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))
2016-06-26 00:10:18 +00:00
.h_align(HAlign::Center)
.button("Quit", |s| s.quit()));
// Show a popup on top of the view.
2016-06-26 00:10:18 +00:00
siv.add_layer(Dialog::new(TextView::new("Try resizing the terminal!\n(Press 'q' to quit \
when you're done.)"))
.dismiss_button("Ok"));
siv.run();
}