2015-05-18 18:36:15 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
|
|
|
use cursive::Cursive;
|
2015-06-03 02:36:22 +00:00
|
|
|
use cursive::align::HAlign;
|
2015-05-22 23:28:05 +00:00
|
|
|
use cursive::view::{TextView,Dialog};
|
2015-05-18 18:36:15 +00:00
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
fn main() {
|
2015-05-22 07:01:23 +00:00
|
|
|
// Read some long text from a file.
|
2015-05-18 18:36:15 +00:00
|
|
|
let mut file = File::open("assets/lorem.txt").unwrap();
|
|
|
|
let mut content = String::new();
|
|
|
|
file.read_to_string(&mut content).unwrap();
|
|
|
|
|
2015-05-25 18:37:28 +00:00
|
|
|
let mut siv = Cursive::new();
|
|
|
|
|
2015-05-18 18:36:15 +00:00
|
|
|
// We can quit by pressing q
|
2015-05-28 01:04:33 +00:00
|
|
|
siv.add_global_callback('q', |s| s.quit());
|
2015-05-18 18:36:15 +00:00
|
|
|
|
2015-05-22 07:01:23 +00:00
|
|
|
// The text is too long to fit on a line, so the view will wrap lines,
|
|
|
|
// and will adapt to the terminal size.
|
2015-05-31 04:53:25 +00:00
|
|
|
siv.add_layer(Dialog::new(TextView::new(&content))
|
2015-06-03 02:36:22 +00:00
|
|
|
.h_align(HAlign::Center)
|
2015-05-31 04:53:25 +00:00
|
|
|
.button("Quit", |s| s.quit()));
|
2015-05-22 07:01:23 +00:00
|
|
|
// Show a popup on top of the view.
|
2015-05-25 08:30:18 +00:00
|
|
|
siv.add_layer(Dialog::new(TextView::new("Try resizing the terminal!\n(Press 'q' to quit when you're done.)"))
|
2015-05-22 07:01:23 +00:00
|
|
|
.dismiss_button("Ok"));
|
2015-05-18 18:36:15 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|
|
|
|
|