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
10
Readme.md
10
Readme.md
@ -21,16 +21,16 @@ 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()));
|
||||||
|
|
||||||
// Starts the event loop.
|
// Starts the event loop.
|
||||||
siv.run();
|
siv.run();
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
|
||||||
use cursive::Cursive;
|
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
|
||||||
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()));
|
||||||
|
|
||||||
|
// Starts the event loop.
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
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() {
|
||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
|
|
||||||
// Create a dialog with an edit text and a button.
|
// Create a dialog with an edit text and a button.
|
||||||
siv.add_layer(Dialog::new(EditView::new().min_length(20).with_id("edit"))
|
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")
|
.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")
|
||||||
if name.is_empty() {
|
.unwrap()
|
||||||
s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
|
.get_content()
|
||||||
.dismiss_button("Ok"));
|
.to_string();
|
||||||
} else {
|
if name.is_empty() {
|
||||||
let content = format!("Hello {}!", name);
|
s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
|
||||||
s.pop_layer();
|
.dismiss_button("Ok"));
|
||||||
s.add_layer(Dialog::new(TextView::new(&content))
|
} else {
|
||||||
.button("Quit", |s| s.quit()));
|
let content = format!("Hello {}!", name);
|
||||||
}
|
s.pop_layer();
|
||||||
}));
|
s.add_layer(Dialog::new(TextView::new(&content))
|
||||||
|
.button("Quit", |s| s.quit()));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@ extern crate cursive;
|
|||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
|
|
||||||
use cursive::view::{View,BoxView};
|
use cursive::view::{View, BoxView};
|
||||||
use cursive::printer::Printer;
|
use cursive::printer::Printer;
|
||||||
use cursive::event::{EventResult,Event};
|
use cursive::event::{EventResult, Event};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut siv = Cursive::new();
|
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();
|
siv.run();
|
||||||
}
|
}
|
||||||
@ -30,8 +30,8 @@ impl KeyCodeView {
|
|||||||
|
|
||||||
impl View for KeyCodeView {
|
impl View for KeyCodeView {
|
||||||
fn draw(&mut self, printer: &Printer) {
|
fn draw(&mut self, printer: &Printer) {
|
||||||
for (y,line) in self.history.iter().enumerate() {
|
for (y, line) in self.history.iter().enumerate() {
|
||||||
printer.print((0,y), &line);
|
printer.print((0, y), &line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,4 +49,3 @@ impl View for KeyCodeView {
|
|||||||
EventResult::Consumed(None)
|
EventResult::Consumed(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::printer::Printer;
|
use cursive::printer::Printer;
|
||||||
use cursive::view::{View,FullView};
|
use cursive::view::{View, FullView};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// As usual, create the Cursive root
|
// As usual, create the Cursive root
|
||||||
@ -17,10 +17,12 @@ fn main() {
|
|||||||
siv.add_global_callback('q', |s| s.quit());
|
siv.add_global_callback('q', |s| s.quit());
|
||||||
|
|
||||||
// A channel will communicate data from our running task to the UI.
|
// 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.
|
// 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
|
||||||
@ -72,7 +74,7 @@ impl BufferView {
|
|||||||
let mut i = self.pos;
|
let mut i = self.pos;
|
||||||
while let Ok(line) = self.rx.try_recv() {
|
while let Ok(line) = self.rx.try_recv() {
|
||||||
self.buffer[i] = line;
|
self.buffer[i] = line;
|
||||||
i = (i+1) % self.buffer.len();
|
i = (i + 1) % self.buffer.len();
|
||||||
}
|
}
|
||||||
self.pos = i;
|
self.pos = i;
|
||||||
}
|
}
|
||||||
@ -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())
|
||||||
@ -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 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.
|
// 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)
|
(self.buffer.len() - printer.size.y as usize, 0)
|
||||||
} else {
|
} else {
|
||||||
(0, printer.size.y - self.buffer.len())
|
(0, printer.size.y - self.buffer.len())
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, line) in self.ring().skip(discard).enumerate() {
|
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::Cursive;
|
||||||
use cursive::align::HAlign;
|
use cursive::align::HAlign;
|
||||||
use cursive::view::{TextView,Dialog};
|
use cursive::view::{TextView, Dialog};
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
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,
|
// The text is too long to fit on a line, so the view will wrap lines,
|
||||||
// and will adapt to the terminal size.
|
// and will adapt to the terminal size.
|
||||||
siv.add_layer(Dialog::new(TextView::new(&content))
|
siv.add_layer(Dialog::new(TextView::new(&content))
|
||||||
.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 \
|
||||||
.dismiss_button("Ok"));
|
when you're done.)"))
|
||||||
|
.dismiss_button("Ok"));
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufReader,BufRead};
|
use std::io::{BufReader, BufRead};
|
||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::align::HAlign;
|
use cursive::align::HAlign;
|
||||||
use cursive::view::{Dialog,SelectView,TextView,BoxView};
|
use cursive::view::{Dialog, SelectView, TextView, BoxView};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// To keep things simple, little error management is done here.
|
// To keep things simple, little error management is done here.
|
||||||
@ -24,8 +24,8 @@ fn main() {
|
|||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
|
|
||||||
// Let's add a BoxView to keep the list at a reasonable size - it can scroll anyway.
|
// 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?"));
|
.title("Where are you from?"));
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
@ -34,5 +34,5 @@ fn main() {
|
|||||||
fn show_next_window(siv: &mut Cursive, city: &String) {
|
fn show_next_window(siv: &mut Cursive, city: &String) {
|
||||||
siv.pop_layer();
|
siv.pop_layer();
|
||||||
siv.add_layer(Dialog::new(TextView::new(&format!("{} is a great city!", city)))
|
siv.add_layer(Dialog::new(TextView::new(&format!("{} is a great city!", city)))
|
||||||
.button("Quit", |s| s.quit()));
|
.button("Quit", |s| s.quit()));
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::view::{Dialog,TextView};
|
use cursive::view::{Dialog, TextView};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
siv.load_theme("assets/style.toml");
|
siv.load_theme("assets/style.toml");
|
||||||
|
|
||||||
siv.add_layer(Dialog::new(TextView::new("This application uses a custom theme!"))
|
siv.add_layer(Dialog::new(TextView::new("This application uses a custom theme!"))
|
||||||
.title("Themed dialog")
|
.title("Themed dialog")
|
||||||
.button("Quit", |s| s.quit()));
|
.button("Quit", |s| s.quit()));
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user