Apply rustfmt to examples

This commit is contained in:
Alexandre Bury 2016-06-25 17:10:18 -07:00
parent a120b2cfe2
commit 654223411d
8 changed files with 59 additions and 52 deletions

View File

@ -21,13 +21,13 @@ cursive = "0.0.1"
extern crate cursive; extern crate cursive;
use cursive::Cursive; use cursive::Cursive;
use cursive::view::{Dialog,TextView}; use cursive::view::{TextView, Dialog};
fn main() { fn main() {
// Creates the cursive root - required for every application. // Creates the cursive root - required for every application.
let mut siv = Cursive::new(); let mut siv = Cursive::new();
// Create a popup window with a button that quits the application // Creates a dialog with a single "Quit" button
siv.add_layer(Dialog::new(TextView::new("Hello Dialog!")) siv.add_layer(Dialog::new(TextView::new("Hello Dialog!"))
.title("Cursive") .title("Cursive")
.button("Quit", |s| s.quit())); .button("Quit", |s| s.quit()));

View File

@ -4,6 +4,7 @@ use cursive::Cursive;
use cursive::view::{TextView, Dialog}; use cursive::view::{TextView, Dialog};
fn main() { fn main() {
// Creates the cursive root - required for every application.
let mut siv = Cursive::new(); let mut siv = Cursive::new();
// Creates a dialog with a single "Quit" button // Creates a dialog with a single "Quit" button
@ -11,5 +12,6 @@ fn main() {
.title("Cursive") .title("Cursive")
.button("Quit", |s| s.quit())); .button("Quit", |s| s.quit()));
// Starts the event loop.
siv.run(); siv.run();
} }

View File

@ -1,6 +1,6 @@
extern crate cursive; extern crate cursive;
use cursive::{Cursive}; use cursive::Cursive;
use cursive::view::{Dialog, EditView, TextView}; use cursive::view::{Dialog, EditView, TextView};
fn main() { fn main() {
@ -12,7 +12,10 @@ fn main() {
.title("Enter your name") .title("Enter your name")
.button("Ok", |s| { .button("Ok", |s| {
// When the button is clicked, read the text and print it in a new dialog. // When the button is clicked, read the text and print it in a new dialog.
let name = s.find_id::<EditView>("edit").unwrap().get_content().to_string(); let name = s.find_id::<EditView>("edit")
.unwrap()
.get_content()
.to_string();
if name.is_empty() { if name.is_empty() {
s.add_layer(Dialog::new(TextView::new("Please enter a name!")) s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
.dismiss_button("Ok")); .dismiss_button("Ok"));

View File

@ -49,4 +49,3 @@ impl View for KeyCodeView {
EventResult::Consumed(None) EventResult::Consumed(None)
} }
} }

View File

@ -20,7 +20,9 @@ fn main() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
// Generate data in a separate thread. // Generate data in a separate thread.
thread::spawn(|| { generate_logs(tx); }); thread::spawn(|| {
generate_logs(tx);
});
// And sets the view to read from the other end of the channel. // And sets the view to read from the other end of the channel.
// (We use FullView to force fullscreen because // (We use FullView to force fullscreen because
@ -80,7 +82,8 @@ impl BufferView {
// Chain together the two parts of the buffer to appear as a circular one. // Chain together the two parts of the buffer to appear as a circular one.
// The signature is quite ugly, but basically we return an iterator: // The signature is quite ugly, but basically we return an iterator:
// a Chain of two slice iterators. // a Chain of two slice iterators.
fn ring<'a>(&'a self) -> std::iter::Chain<std::slice::Iter<'a,String>, std::slice::Iter<'a,String>> { fn ring<'a>(&'a self)
-> std::iter::Chain<std::slice::Iter<'a, String>, std::slice::Iter<'a, String>> {
// The main buffer is "circular" starting at self.pos // The main buffer is "circular" starting at self.pos
// So we chain the two parts as one // So we chain the two parts as one
self.buffer[self.pos..].iter().chain(self.buffer[..self.pos].iter()) self.buffer[self.pos..].iter().chain(self.buffer[..self.pos].iter())

View File

@ -24,9 +24,9 @@ fn main() {
.h_align(HAlign::Center) .h_align(HAlign::Center)
.button("Quit", |s| s.quit())); .button("Quit", |s| s.quit()));
// Show a popup on top of the view. // 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.)")) siv.add_layer(Dialog::new(TextView::new("Try resizing the terminal!\n(Press 'q' to quit \
when you're done.)"))
.dismiss_button("Ok")); .dismiss_button("Ok"));
siv.run(); siv.run();
} }