mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Apply rustfmt to examples
This commit is contained in:
parent
a120b2cfe2
commit
654223411d
@ -21,13 +21,13 @@ 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.
|
||||
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()));
|
||||
|
@ -1,9 +1,10 @@
|
||||
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
|
||||
@ -11,5 +12,6 @@ fn main() {
|
||||
.title("Cursive")
|
||||
.button("Quit", |s| s.quit()));
|
||||
|
||||
// Starts the event loop.
|
||||
siv.run();
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
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))
|
||||
.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::<EditView>("edit").unwrap().get_content().to_string();
|
||||
let name = s.find_id::<EditView>("edit")
|
||||
.unwrap()
|
||||
.get_content()
|
||||
.to_string();
|
||||
if name.is_empty() {
|
||||
s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
|
||||
.dismiss_button("Ok"));
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>, 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
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -24,9 +24,9 @@ fn main() {
|
||||
.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.)"))
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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,7 +24,7 @@ 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))
|
||||
siv.add_layer(Dialog::new(BoxView::new((20, 10), select))
|
||||
.title("Where are you from?"));
|
||||
|
||||
siv.run();
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::view::{Dialog,TextView};
|
||||
use cursive::view::{Dialog, TextView};
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
Loading…
Reference in New Issue
Block a user