diff --git a/Readme.md b/Readme.md index 602668d..3c5a438 100644 --- a/Readme.md +++ b/Readme.md @@ -21,16 +21,16 @@ cursive = "0.0.1" extern crate cursive; use cursive::Cursive; -use cursive::view::{Dialog,TextView}; +use cursive::view::{TextView, Dialog}; fn main() { - // Creates the cursive root - required for every application. + // Creates the cursive root - required for every application. 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!")) - .title("Cursive") - .button("Quit", |s| s.quit())); + .title("Cursive") + .button("Quit", |s| s.quit())); // Starts the event loop. siv.run(); diff --git a/examples/dialog.rs b/examples/dialog.rs index 03467c9..00535a0 100644 --- a/examples/dialog.rs +++ b/examples/dialog.rs @@ -1,15 +1,17 @@ extern crate cursive; use cursive::Cursive; -use cursive::view::{TextView,Dialog}; +use cursive::view::{TextView, Dialog}; fn main() { + // Creates the cursive root - required for every application. let mut siv = Cursive::new(); // Creates a dialog with a single "Quit" button siv.add_layer(Dialog::new(TextView::new("Hello Dialog!")) - .title("Cursive") - .button("Quit", |s| s.quit())); + .title("Cursive") + .button("Quit", |s| s.quit())); + // Starts the event loop. siv.run(); } diff --git a/examples/edit.rs b/examples/edit.rs index 1b6b7c0..397d009 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -1,28 +1,31 @@ extern crate cursive; -use cursive::{Cursive}; -use cursive::view::{Dialog,EditView,TextView}; +use cursive::Cursive; +use cursive::view::{Dialog, EditView, TextView}; fn main() { let mut siv = Cursive::new(); // Create a dialog with an edit text and a button. siv.add_layer(Dialog::new(EditView::new().min_length(20).with_id("edit")) - .padding((1,1,1,0)) - .title("Enter your name") - .button("Ok", |s| { - // When the button is clicked, read the text and print it in a new dialog. - let name = s.find_id::("edit").unwrap().get_content().to_string(); - if name.is_empty() { - s.add_layer(Dialog::new(TextView::new("Please enter a name!")) - .dismiss_button("Ok")); - } else { - let content = format!("Hello {}!", name); - s.pop_layer(); - s.add_layer(Dialog::new(TextView::new(&content)) - .button("Quit", |s| s.quit())); - } - })); + .padding((1, 1, 1, 0)) + .title("Enter your name") + .button("Ok", |s| { + // When the button is clicked, read the text and print it in a new dialog. + let name = s.find_id::("edit") + .unwrap() + .get_content() + .to_string(); + if name.is_empty() { + s.add_layer(Dialog::new(TextView::new("Please enter a name!")) + .dismiss_button("Ok")); + } else { + let content = format!("Hello {}!", name); + s.pop_layer(); + s.add_layer(Dialog::new(TextView::new(&content)) + .button("Quit", |s| s.quit())); + } + })); siv.run(); } diff --git a/examples/key_codes.rs b/examples/key_codes.rs index 0d9e7a8..32c22a0 100644 --- a/examples/key_codes.rs +++ b/examples/key_codes.rs @@ -2,14 +2,14 @@ extern crate cursive; use cursive::Cursive; -use cursive::view::{View,BoxView}; +use cursive::view::{View, BoxView}; use cursive::printer::Printer; -use cursive::event::{EventResult,Event}; +use cursive::event::{EventResult, Event}; fn main() { let mut siv = Cursive::new(); - siv.add_layer(BoxView::new((30,10), KeyCodeView::new(10))); + siv.add_layer(BoxView::new((30, 10), KeyCodeView::new(10))); siv.run(); } @@ -30,8 +30,8 @@ impl KeyCodeView { impl View for KeyCodeView { fn draw(&mut self, printer: &Printer) { - for (y,line) in self.history.iter().enumerate() { - printer.print((0,y), &line); + for (y, line) in self.history.iter().enumerate() { + printer.print((0, y), &line); } } @@ -49,4 +49,3 @@ impl View for KeyCodeView { EventResult::Consumed(None) } } - diff --git a/examples/logs.rs b/examples/logs.rs index 7caf293..c13875a 100644 --- a/examples/logs.rs +++ b/examples/logs.rs @@ -6,7 +6,7 @@ use std::time::Duration; use cursive::Cursive; use cursive::printer::Printer; -use cursive::view::{View,FullView}; +use cursive::view::{View, FullView}; fn main() { // As usual, create the Cursive root @@ -17,10 +17,12 @@ fn main() { siv.add_global_callback('q', |s| s.quit()); // A channel will communicate data from our running task to the UI. - let (tx,rx) = mpsc::channel(); + let (tx, rx) = mpsc::channel(); // 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. // (We use FullView to force fullscreen because @@ -72,7 +74,7 @@ impl BufferView { let mut i = self.pos; while let Ok(line) = self.rx.try_recv() { self.buffer[i] = line; - i = (i+1) % self.buffer.len(); + i = (i + 1) % self.buffer.len(); } self.pos = i; } @@ -80,7 +82,8 @@ impl BufferView { // 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: // a Chain of two slice iterators. - fn ring<'a>(&'a self) -> std::iter::Chain, std::slice::Iter<'a,String>> { + fn ring<'a>(&'a self) + -> std::iter::Chain, std::slice::Iter<'a, String>> { // The main buffer is "circular" starting at self.pos // So we chain the two parts as one self.buffer[self.pos..].iter().chain(self.buffer[..self.pos].iter()) @@ -94,14 +97,14 @@ impl View for BufferView { // If the buffer is large enough, we'll discard the beginning and keep the end. // If the buffer is too small, only print a part of it with an offset. - let (discard,offset) = if self.buffer.len() > printer.size.y as usize { + let (discard, offset) = if self.buffer.len() > printer.size.y as usize { (self.buffer.len() - printer.size.y as usize, 0) } else { (0, printer.size.y - self.buffer.len()) }; for (i, line) in self.ring().skip(discard).enumerate() { - printer.print((0,offset + i), line); + printer.print((0, offset + i), line); } } } diff --git a/examples/lorem.rs b/examples/lorem.rs index 569f468..8ec115a 100644 --- a/examples/lorem.rs +++ b/examples/lorem.rs @@ -2,7 +2,7 @@ extern crate cursive; use cursive::Cursive; use cursive::align::HAlign; -use cursive::view::{TextView,Dialog}; +use cursive::view::{TextView, Dialog}; use std::fs::File; use std::io::Read; @@ -21,12 +21,12 @@ fn main() { // 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)) - .h_align(HAlign::Center) - .button("Quit", |s| s.quit())); + .h_align(HAlign::Center) + .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.)")) - .dismiss_button("Ok")); + 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(); } - diff --git a/examples/select.rs b/examples/select.rs index 1e1d717..28566d7 100644 --- a/examples/select.rs +++ b/examples/select.rs @@ -1,11 +1,11 @@ extern crate cursive; use std::fs::File; -use std::io::{BufReader,BufRead}; +use std::io::{BufReader, BufRead}; use cursive::Cursive; use cursive::align::HAlign; -use cursive::view::{Dialog,SelectView,TextView,BoxView}; +use cursive::view::{Dialog, SelectView, TextView, BoxView}; fn main() { // To keep things simple, little error management is done here. @@ -24,8 +24,8 @@ fn main() { let mut siv = Cursive::new(); // Let's add a BoxView to keep the list at a reasonable size - it can scroll anyway. - siv.add_layer(Dialog::new(BoxView::new((20,10), select)) - .title("Where are you from?")); + siv.add_layer(Dialog::new(BoxView::new((20, 10), select)) + .title("Where are you from?")); siv.run(); } @@ -34,5 +34,5 @@ fn main() { fn show_next_window(siv: &mut Cursive, city: &String) { siv.pop_layer(); siv.add_layer(Dialog::new(TextView::new(&format!("{} is a great city!", city))) - .button("Quit", |s| s.quit())); + .button("Quit", |s| s.quit())); } diff --git a/examples/theme.rs b/examples/theme.rs index b2e1581..1028cee 100644 --- a/examples/theme.rs +++ b/examples/theme.rs @@ -1,15 +1,15 @@ extern crate cursive; use cursive::Cursive; -use cursive::view::{Dialog,TextView}; +use cursive::view::{Dialog, TextView}; fn main() { let mut siv = Cursive::new(); siv.load_theme("assets/style.toml"); siv.add_layer(Dialog::new(TextView::new("This application uses a custom theme!")) - .title("Themed dialog") - .button("Quit", |s| s.quit())); + .title("Themed dialog") + .button("Quit", |s| s.quit())); siv.run(); }