mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-09 10:50:40 +00:00
Improved lorem example
TODO: add margins around the textview?
This commit is contained in:
parent
25726140d8
commit
3df17cc64b
@ -2,6 +2,7 @@ extern crate cursive;
|
|||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::view::TextView;
|
use cursive::view::TextView;
|
||||||
|
use cursive::view::Dialog;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
@ -9,7 +10,7 @@ use std::io::Read;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
|
|
||||||
// Read some long text to showcase the layout
|
// Read some long text from a file.
|
||||||
let mut file = File::open("assets/lorem.txt").unwrap();
|
let mut file = File::open("assets/lorem.txt").unwrap();
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
file.read_to_string(&mut content).unwrap();
|
file.read_to_string(&mut content).unwrap();
|
||||||
@ -17,7 +18,12 @@ fn main() {
|
|||||||
// We can quit by pressing q
|
// We can quit by pressing q
|
||||||
siv.add_global_callback('q' as i32, |s,_| s.quit());
|
siv.add_global_callback('q' as i32, |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(TextView::new(&content));
|
siv.add_layer(TextView::new(&content));
|
||||||
|
// 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)"))
|
||||||
|
.dismiss_button("Ok"));
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,13 @@ impl Dialog {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shortcut method to add a button that will dismiss the dialog.
|
||||||
|
pub fn dismiss_button<'a>(self, label: &'a str) -> Self {
|
||||||
|
self.button(label, |s, _| s.screen_mut().pop_layer())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the title of the dialog.
|
||||||
|
/// If not empty, it will be visible at the top.
|
||||||
pub fn title(mut self, label: &str) -> Self {
|
pub fn title(mut self, label: &str) -> Self {
|
||||||
self.title = label.to_string();
|
self.title = label.to_string();
|
||||||
self
|
self
|
||||||
|
Loading…
Reference in New Issue
Block a user