mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Update examples and tutorials to Rust 2018
This commit is contained in:
parent
b2184b3a36
commit
23d65aa9dc
@ -30,8 +30,6 @@ cursive = { git = "https://github.com/gyscos/Cursive" }
|
||||
([You will also need ncurses installed.](https://github.com/gyscos/Cursive/wiki/Install-ncurses))
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
|
||||
|
@ -6,8 +6,6 @@ In this first tutorial, we'll learn the basics of cursive,
|
||||
and write a very basic first application:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::TextView;
|
||||
|
||||
@ -51,8 +49,6 @@ cursive = "*"
|
||||
Finally, update `src/main.rs` to import it:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
fn main() {
|
||||
}
|
||||
```
|
||||
@ -75,8 +71,6 @@ so let's skip it for now.
|
||||
In its simplest form, a cursive application is therefore:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
@ -112,8 +106,6 @@ This method takes 2 arguments: a trigger, and a callback.
|
||||
In the end, we have:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
@ -153,8 +145,6 @@ exactly that.
|
||||
Once we've added this line, our first application is complete:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::TextView;
|
||||
|
||||
|
@ -6,8 +6,6 @@ This time, we'll work on a slightly bigger example, where the user will need to
|
||||
actually make some choices. Here is what the code will look like:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::Dialog;
|
||||
|
||||
@ -46,8 +44,6 @@ This time you're not a beginner anymore, so we'll skip the introduction!
|
||||
Let's start from a basic cursive application:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
|
||||
fn main() {
|
||||
@ -67,8 +63,6 @@ and/or buttons.
|
||||
`TextView`:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::Dialog;
|
||||
use cursive::views::TextView;
|
||||
@ -129,8 +123,6 @@ packing everything into the closure, let's use a separate function for the
|
||||
callback. Here is the current state:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::Dialog;
|
||||
|
||||
|
@ -9,8 +9,6 @@ them to update them.
|
||||
Here is the code we'll end up with:
|
||||
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Button, Dialog, DummyView, EditView,
|
||||
LinearLayout, SelectView};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::theme::{Color, ColorStyle};
|
||||
use cursive::view::Boxable;
|
||||
use cursive::views::Canvas;
|
||||
|
@ -1,24 +1,19 @@
|
||||
extern crate cursive;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
fn main() {
|
||||
// Initialize the cursive logger.
|
||||
cursive::logger::init();
|
||||
|
||||
// Use some logging macros from the `log` crate.
|
||||
error!("Something serious probably happened!");
|
||||
warn!("Or did it?");
|
||||
debug!("Logger initialized.");
|
||||
info!("Starting!");
|
||||
log::error!("Something serious probably happened!");
|
||||
log::warn!("Or did it?");
|
||||
log::debug!("Logger initialized.");
|
||||
log::info!("Starting!");
|
||||
|
||||
let mut siv = cursive::Cursive::default();
|
||||
siv.add_layer(cursive::views::Dialog::text("Press ~ to open the console.\nPress l to generate logs.\nPress q to quit."));
|
||||
siv.add_global_callback('q', cursive::Cursive::quit);
|
||||
siv.add_global_callback('~', cursive::Cursive::toggle_debug_console);
|
||||
|
||||
siv.add_global_callback('l', |_| trace!("Wooo"));
|
||||
siv.add_global_callback('l', |_| log::trace!("Wooo"));
|
||||
|
||||
siv.run();
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::views::{CircularFocus, Dialog, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, EditView, TextView};
|
||||
use cursive::Cursive;
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::views::TextView;
|
||||
use cursive::Cursive;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::event::{Event, EventResult};
|
||||
use cursive::traits::*;
|
||||
use cursive::{Cursive, Printer};
|
||||
@ -24,7 +22,7 @@ impl KeyCodeView {
|
||||
fn new(size: usize) -> Self {
|
||||
KeyCodeView {
|
||||
history: Vec::new(),
|
||||
size: size,
|
||||
size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::align::HAlign;
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, DummyView, LinearLayout, TextView};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{
|
||||
Checkbox, Dialog, EditView, LinearLayout, ListView, SelectView, TextView,
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::*;
|
||||
use cursive::vec::Vec2;
|
||||
use cursive::{Cursive, Printer};
|
||||
@ -65,10 +63,7 @@ impl BufferView {
|
||||
fn new(size: usize, rx: mpsc::Receiver<String>) -> Self {
|
||||
let mut buffer = VecDeque::new();
|
||||
buffer.resize(size, String::new());
|
||||
BufferView {
|
||||
rx: rx,
|
||||
buffer: buffer,
|
||||
}
|
||||
BufferView { rx, buffer }
|
||||
}
|
||||
|
||||
// Reads available data from the stream into the buffer
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::align::HAlign;
|
||||
use cursive::view::Scrollable;
|
||||
use cursive::views::{Dialog, Panel, TextView};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::theme::BaseColor;
|
||||
use cursive::theme::Color;
|
||||
use cursive::theme::Effect;
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::event::Key;
|
||||
use cursive::menu::MenuTree;
|
||||
use cursive::traits::*;
|
||||
|
@ -1,6 +1,3 @@
|
||||
extern crate cursive;
|
||||
extern crate rand;
|
||||
|
||||
mod game;
|
||||
|
||||
use cursive::direction::Direction;
|
||||
@ -148,7 +145,7 @@ impl BoardView {
|
||||
}
|
||||
}
|
||||
}
|
||||
return EventResult::Consumed(None);
|
||||
EventResult::Consumed(None)
|
||||
}
|
||||
|
||||
fn auto_reveal(&mut self, pos: Vec2) -> EventResult {
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::*;
|
||||
use cursive::view::{Offset, Position};
|
||||
use cursive::views::{Dialog, OnEventView, TextView};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::view::Position;
|
||||
use cursive::views::LayerPosition;
|
||||
use cursive::views::TextView;
|
||||
|
@ -1,6 +1,3 @@
|
||||
extern crate cursive;
|
||||
extern crate rand;
|
||||
|
||||
use cursive::traits::*;
|
||||
use cursive::utils::Counter;
|
||||
use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, TextView};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::views::{Dialog, DummyView, LinearLayout, RadioGroup};
|
||||
use cursive::Cursive;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::view::{Boxable, Identifiable};
|
||||
use cursive::views::{Dialog, EditView, LinearLayout, TextView};
|
||||
use cursive::Cursive;
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::Boxable;
|
||||
use cursive::view::Scrollable;
|
||||
use cursive::views::{Button, Canvas, Dialog, LinearLayout};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::align::HAlign;
|
||||
use cursive::event::EventResult;
|
||||
use cursive::traits::*;
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, SliderView};
|
||||
use cursive::Cursive;
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::theme::{Color, PaletteColor, Theme};
|
||||
use cursive::views::TextView;
|
||||
use cursive::Cursive;
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::event::{Event, Key};
|
||||
use cursive::traits::*;
|
||||
use cursive::views::{Dialog, EditView, OnEventView, TextArea};
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::theme::{BaseColor, BorderStyle, Color, ColorStyle};
|
||||
use cursive::views::{Dialog, EditView, LinearLayout, TextView};
|
||||
use cursive::Cursive;
|
||||
|
@ -47,7 +47,8 @@ fn main() {
|
||||
let duration = now - start;
|
||||
|
||||
let seconds = duration.as_secs() as f64
|
||||
+ duration.subsec_nanos() as f64 * 1e-9;
|
||||
+ f64::from(duration.subsec_nanos())
|
||||
* 1e-9;
|
||||
|
||||
let speed = ticks / seconds;
|
||||
|
||||
|
@ -325,7 +325,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
@ -358,8 +357,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// #
|
||||
/// # use cursive::{Cursive, event};
|
||||
/// # use cursive::views::{Dialog};
|
||||
/// # use cursive::traits::*;
|
||||
@ -512,7 +509,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::{Cursive, views, view};
|
||||
/// # use cursive::traits::*;
|
||||
/// # fn main() {
|
||||
@ -550,7 +546,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::{Cursive, views};
|
||||
/// # use cursive::traits::*;
|
||||
/// # fn main() {
|
||||
@ -645,7 +640,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
@ -668,7 +662,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
@ -690,7 +683,6 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
|
@ -33,8 +33,6 @@
|
||||
//! ## Examples
|
||||
//!
|
||||
//! ```rust
|
||||
//! extern crate cursive;
|
||||
//!
|
||||
//! use cursive::Cursive;
|
||||
//! use cursive::views::TextView;
|
||||
//!
|
||||
|
@ -52,9 +52,7 @@ pub fn immutify<F: FnMut(&mut Cursive)>(
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # #[macro_use]
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::{Cursive, immut1};
|
||||
/// # fn main() {
|
||||
/// # let mut siv = Cursive::dummy();
|
||||
/// let mut i = 0;
|
||||
|
@ -39,8 +39,6 @@ pub fn make_lines(content: &str, width: usize) -> Vec<Row> {
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// extern crate unicode_segmentation;
|
||||
/// use unicode_segmentation::UnicodeSegmentation;
|
||||
///
|
||||
/// # use cursive::utils::lines::simple::prefix;
|
||||
|
@ -154,14 +154,13 @@ impl<T: ViewWrapper> View for T {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # #[macro_use] extern crate cursive;
|
||||
/// # use cursive::view::{View,ViewWrapper};
|
||||
/// struct FooView<T: View> {
|
||||
/// view: T,
|
||||
/// }
|
||||
///
|
||||
/// impl <T: View> ViewWrapper for FooView<T> {
|
||||
/// wrap_impl!(self.view: T);
|
||||
/// cursive::wrap_impl!(self.view: T);
|
||||
/// }
|
||||
/// # fn main() { }
|
||||
/// ```
|
||||
@ -199,18 +198,17 @@ macro_rules! wrap_impl {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # #[macro_use] extern crate cursive;
|
||||
/// # use cursive::view::{View,ViewWrapper};
|
||||
/// # use cursive::view::{View, ViewWrapper};
|
||||
/// struct FooView<T: View> {
|
||||
/// view: T,
|
||||
/// }
|
||||
///
|
||||
/// impl<T: View> FooView<T> {
|
||||
/// inner_getters!(self.view: T);
|
||||
/// cursive::inner_getters!(self.view: T);
|
||||
/// }
|
||||
///
|
||||
/// impl <T: View> ViewWrapper for FooView<T> {
|
||||
/// wrap_impl!(self.view: T);
|
||||
/// cursive::wrap_impl!(self.view: T);
|
||||
/// }
|
||||
/// # fn main() { }
|
||||
/// ```
|
||||
|
@ -31,7 +31,6 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// [1]: https://github.com/gyscos/Cursive/blob/master/examples/edit.rs
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::traits::*;
|
||||
/// # use cursive::views::{Dialog, EditView, TextView};
|
||||
|
@ -25,7 +25,6 @@ use std::rc::Rc;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::views::{SelectView, Dialog, TextView};
|
||||
/// # use cursive::align::HAlign;
|
||||
|
Loading…
Reference in New Issue
Block a user