mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Remove prelude
module
Add `traits` module instead
This commit is contained in:
parent
51e955808c
commit
d684a5bc1e
@ -23,10 +23,10 @@ version = "5.82.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.3"
|
||||
skeptic = "0.5"
|
||||
skeptic = "*"
|
||||
|
||||
[build-dependencies]
|
||||
skeptic = "0.5"
|
||||
skeptic = "*"
|
||||
|
||||
[lib]
|
||||
name = "cursive"
|
||||
|
@ -29,7 +29,8 @@ cursive = { git = "https://github.com/gyscos/Cursive" }
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
|
||||
fn main() {
|
||||
// Creates the cursive root - required for every application.
|
||||
|
@ -112,8 +112,6 @@ This method takes 2 arguments: a trigger, and a callback.
|
||||
In the end, we have:
|
||||
|
||||
```rust,no_run
|
||||
# src/main.rs
|
||||
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::Cursive;
|
||||
|
@ -11,7 +11,10 @@ Here is the code we'll end up with:
|
||||
```rust,no_run
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Button, Dialog, DummyView, EditView,
|
||||
LinearLayout, SelectView};
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
@ -98,9 +101,12 @@ let select = BoxView::with_fixed_size((10, 5), SelectView::<String>::new());
|
||||
|
||||
But there is another shorter way: the [`Boxable`] trait is conveniently
|
||||
implemented for any `View`, and allow to wrap in a `BoxView` with a chainable
|
||||
call:
|
||||
call. `Boxable`, and a few other useful traits, are conveniently bundled in
|
||||
the [`traits`] prelude, ready to be imported:
|
||||
|
||||
```rust,ignore
|
||||
use cursive::traits::*;
|
||||
|
||||
let select = SelectView::<String>::new()
|
||||
.fixed_size((10, 5));
|
||||
```
|
||||
@ -132,6 +138,7 @@ replace the layer with a simple dialog.
|
||||
[`SelectView`]: http://gyscos.github.io/Cursive/cursive/views/struct.SelectView.html
|
||||
[`BoxView`]: http://gyscos.github.io/Cursive/cursive/views/struct.BoxView.html
|
||||
[`Boxable`]: http://gyscos.github.io/Cursive/cursive/view/trait.Boxable.html
|
||||
[`traits`]: http://gyscos.github.io/Cursive/cursive/traits/index.html
|
||||
[`SelectView::on_submit`]: http://gyscos.github.io/Cursive/cursive/views/struct.SelectView.html#method.on_submit
|
||||
|
||||
## Linear layouts
|
||||
|
@ -1,6 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
|
||||
fn main() {
|
||||
// Creates the cursive root - required for every application.
|
||||
|
@ -1,6 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, EditView, TextView};
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,6 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::TextView;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,7 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::event::EventResult;
|
||||
use cursive::{Cursive, Printer};
|
||||
use cursive::traits::*;
|
||||
use cursive::event::{Event, EventResult};
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,7 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, LinearLayout, TextView};
|
||||
use cursive::align::HAlign;
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,6 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Checkbox, Dialog, EditView, LinearLayout, ListView,
|
||||
SelectView, TextView};
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,6 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::{Cursive, Printer};
|
||||
use cursive::vec::Vec2;
|
||||
use cursive::traits::*;
|
||||
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
|
@ -1,6 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::align::HAlign;
|
||||
|
||||
fn main() {
|
||||
|
@ -1,6 +1,10 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::menu::MenuTree;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
use cursive::event::Key;
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
|
||||
@ -10,7 +14,8 @@ fn main() {
|
||||
.add("File",
|
||||
MenuTree::new()
|
||||
.leaf("New", |s| s.add_layer(Dialog::info("New file!")))
|
||||
.subtree("Recent", MenuTree::new().with(|tree| {
|
||||
.subtree("Recent",
|
||||
MenuTree::new().with(|tree| {
|
||||
for i in 1..100 {
|
||||
tree.add_leaf(&format!("Item {}", i), |_| ())
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::view::{Position, Offset};
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, KeyEventView, TextView};
|
||||
use cursive::view::{Offset, Position};
|
||||
use cursive::traits::*;
|
||||
|
||||
fn show_popup(siv: &mut Cursive) {
|
||||
|
||||
@ -22,14 +24,15 @@ fn show_popup(siv: &mut Cursive) {
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
let content = "Press Q to quit the application.\n\nPress P to open the popup.";
|
||||
let content = "Press Q to quit the application.\n\nPress P to open the \
|
||||
popup.";
|
||||
|
||||
siv.add_global_callback('q', |s| s.quit());
|
||||
|
||||
// Let's wrap the view to give it a recognizable ID, so we can look for it.
|
||||
// We add the P callback on the textview only (and not globally),
|
||||
// so that we can't call it when the popup is already visible.
|
||||
siv.add_layer(KeyEventView::new(IdView::new("text", TextView::new(content)))
|
||||
siv.add_layer(KeyEventView::new(TextView::new(content).with_id("text"))
|
||||
.register('p', |s| show_popup(s)));
|
||||
|
||||
|
||||
|
@ -3,8 +3,10 @@ extern crate rand;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, TextView};
|
||||
use cursive::views::Counter;
|
||||
use cursive::traits::*;
|
||||
|
||||
use std::thread;
|
||||
use std::cmp::min;
|
||||
@ -88,8 +90,7 @@ fn phase_2(s: &mut Cursive) {
|
||||
}
|
||||
|
||||
s.pop_layer();
|
||||
s.add_layer(Dialog::new(linear.full_width())
|
||||
.title("Just a moment..."));
|
||||
s.add_layer(Dialog::new(linear.full_width()).title("Just a moment..."));
|
||||
|
||||
// And we start the worker thread.
|
||||
thread::spawn(move || {
|
||||
|
@ -1,7 +1,9 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, SelectView, TextView};
|
||||
use cursive::align::HAlign;
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut select = SelectView::new().h_align(HAlign::Center);
|
||||
|
@ -1,6 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, SliderView};
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,6 +1,8 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextArea};
|
||||
use cursive::traits::*;
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
@ -1,6 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::{Dialog, TextView};
|
||||
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
@ -10,7 +11,8 @@ fn main() {
|
||||
// Or you can directly load it from a string for easy deployment.
|
||||
// siv.load_theme(include_str!("../assets/style.toml")).unwrap();
|
||||
|
||||
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")
|
||||
.button("Quit", |s| s.quit()));
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
extern crate cursive;
|
||||
|
||||
use cursive::prelude::*;
|
||||
use cursive::Cursive;
|
||||
use cursive::views::Dialog;
|
||||
use cursive::theme::BorderStyle;
|
||||
|
||||
fn main() {
|
||||
|
36
src/lib.rs
36
src/lib.rs
@ -33,12 +33,12 @@
|
||||
//! ```no_run
|
||||
//! extern crate cursive;
|
||||
//!
|
||||
//! use cursive::prelude::*;
|
||||
//! use cursive::*;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let mut siv = Cursive::new();
|
||||
//!
|
||||
//! siv.add_layer(TextView::new("Hello World!\nPress q to quit."));
|
||||
//! siv.add_layer(views::TextView::new("Hello World!\nPress q to quit."));
|
||||
//!
|
||||
//! siv.add_global_callback('q', |s| s.quit());
|
||||
//!
|
||||
@ -80,7 +80,7 @@ macro_rules! new_default(
|
||||
}
|
||||
);
|
||||
|
||||
pub mod prelude;
|
||||
pub mod traits;
|
||||
|
||||
pub mod event;
|
||||
#[macro_use]
|
||||
@ -216,10 +216,12 @@ impl Cursive {
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// #
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::{Cursive, event};
|
||||
/// # use cursive::views::{Dialog};
|
||||
/// # use cursive::traits::*;
|
||||
/// # use cursive::menu::*;
|
||||
/// #
|
||||
/// # fn main() {
|
||||
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.menubar()
|
||||
@ -252,7 +254,7 @@ impl Cursive {
|
||||
/// .leaf("About",
|
||||
/// |s| s.add_layer(Dialog::info("Cursive v0.0.0"))));
|
||||
///
|
||||
/// siv.add_global_callback(Key::Esc, |s| s.select_menubar());
|
||||
/// siv.add_global_callback(event::Key::Esc, |s| s.select_menubar());
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn menubar(&mut self) -> &mut views::Menubar {
|
||||
@ -343,14 +345,16 @@ impl Cursive {
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::{Cursive, views, view};
|
||||
/// # use cursive::traits::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.add_layer(IdView::new("text", TextView::new("Text #1")));
|
||||
/// siv.add_layer(views::TextView::new("Text #1")
|
||||
/// .with_id("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.find::<TextView>(&Selector::Id("text"))
|
||||
/// s.find::<views::TextView>(&view::Selector::Id("text"))
|
||||
/// .unwrap()
|
||||
/// .set_content("Text #2");
|
||||
/// });
|
||||
@ -367,14 +371,16 @@ impl Cursive {
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::{Cursive, views};
|
||||
/// # use cursive::traits::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.add_layer(IdView::new("text", TextView::new("Text #1")));
|
||||
/// siv.add_layer(views::TextView::new("Text #1")
|
||||
/// .with_id("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.find_id::<TextView>("text")
|
||||
/// s.find_id::<views::TextView>("text")
|
||||
/// .unwrap()
|
||||
/// .set_content("Text #2");
|
||||
/// });
|
||||
@ -392,7 +398,7 @@ impl Cursive {
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
@ -411,11 +417,11 @@ impl Cursive {
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.add_layer(TextView::new("Hello world!"));
|
||||
/// siv.add_layer(views::TextView::new("Hello world!"));
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn add_layer<T: 'static + View>(&mut self, view: T) {
|
||||
|
@ -1,27 +0,0 @@
|
||||
//! Commonly used imports, conveniently grouped.
|
||||
//!
|
||||
//! To easily import a bunch of commonly-used definitions, import this bundle:
|
||||
//!
|
||||
//! ```
|
||||
//! use cursive::prelude::*;
|
||||
//! ```
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use {Cursive, Printer, With};
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use event::{Event, Key};
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use view::{Boxable, Finder, Identifiable, Selector, View};
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use views::{BoxView, Button, Checkbox, Dialog, DummyView, EditView,
|
||||
IdView, KeyEventView, LinearLayout, ListView, Panel,
|
||||
ProgressBar, SelectView, SliderView, TextArea, TextView};
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use vec::Vec2;
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use menu::MenuTree;
|
15
src/traits.rs
Normal file
15
src/traits.rs
Normal file
@ -0,0 +1,15 @@
|
||||
//! Commonly used traits bundled for easy import.
|
||||
//!
|
||||
//! This module provides an easy way to import some traits.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```
|
||||
//! use cursive::traits::*;
|
||||
//! ```
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use With;
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use view::{Boxable, Finder, Identifiable, View};
|
@ -15,7 +15,7 @@ use view::View;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::views::Button;
|
||||
/// let quit_button = Button::new("Quit", |s| s.quit());
|
||||
/// ```
|
||||
pub struct Button {
|
||||
|
@ -22,7 +22,9 @@ use utils::simple_suffix_length;
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::traits::*;
|
||||
/// # use cursive::views::{Dialog, EditView, TextView};
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
|
@ -11,10 +11,11 @@ use view::{View, ViewWrapper};
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::event;;
|
||||
/// # use cursive::views::{KeyEventView, TextView};
|
||||
/// let view = KeyEventView::new(TextView::new("This view has an event!"))
|
||||
/// .register('q', |s| s.quit())
|
||||
/// .register(Key::Esc, |s| s.quit());
|
||||
/// .register(event::Key::Esc, |s| s.quit());
|
||||
/// ```
|
||||
pub struct KeyEventView<T: View> {
|
||||
content: T,
|
||||
|
@ -49,7 +49,7 @@ impl Counter {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::views::ProgressBar;
|
||||
/// let bar = ProgressBar::new()
|
||||
/// .with_task(|counter| {
|
||||
/// // This closure is called in parallel.
|
||||
|
@ -25,7 +25,8 @@ use unicode_width::UnicodeWidthStr;
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate cursive;
|
||||
/// # use cursive::prelude::*;
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::views::{SelectView, Dialog, TextView};
|
||||
/// # use cursive::align::HAlign;
|
||||
/// # fn main() {
|
||||
/// let mut time_select = SelectView::new().h_align(HAlign::Center);
|
||||
|
Loading…
Reference in New Issue
Block a user