mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix doc-tests
This commit is contained in:
parent
1e42631fb3
commit
cb523e88ae
@ -293,7 +293,7 @@ impl From<io::Error> for Error {
|
||||
///
|
||||
/// Here is an example file:
|
||||
///
|
||||
/// ```
|
||||
/// ```text
|
||||
/// background = "#5555FF"
|
||||
/// shadow = "#000000"
|
||||
/// view = "#888888"
|
||||
|
@ -4,7 +4,7 @@
|
||||
//! It allows to easily build layouts for text-based applications.
|
||||
//!
|
||||
//! ## Example
|
||||
//! ```
|
||||
//! ```no_run
|
||||
//! extern crate cursive;
|
||||
//!
|
||||
//! use cursive::Cursive;
|
||||
@ -15,7 +15,7 @@
|
||||
//!
|
||||
//! siv.add_layer(TextView::new("Hello World!\nPress q to quit."));
|
||||
//!
|
||||
//! siv.add_global_callback('q' as i32, |s| s.quit());
|
||||
//! siv.add_global_callback('q', |s| s.quit());
|
||||
//!
|
||||
//! siv.run();
|
||||
//! }
|
||||
|
@ -73,6 +73,9 @@ impl Printer {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::printer::Printer;
|
||||
/// # use cursive::color;
|
||||
/// # let printer = Printer::new((6,4));
|
||||
/// printer.with_color(color::HIGHLIGHT, |printer| {
|
||||
/// printer.print((0,0), "This text is highlighted!");
|
||||
/// });
|
||||
@ -103,6 +106,8 @@ impl Printer {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::printer::Printer;
|
||||
/// # let printer = Printer::new((6,4));
|
||||
/// printer.print_box((0,0), (6,4));
|
||||
/// ```
|
||||
pub fn print_box<T: ToVec2>(&self, start: T, size: T) {
|
||||
|
@ -14,8 +14,9 @@ impl BoxView {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::view::{BoxView,TextView};
|
||||
/// // Creates a 20x4 BoxView with a TextView content.
|
||||
/// let box = BoxView::new((20,4), TextView::new("Hello!"))
|
||||
/// let view = BoxView::new((20,4), TextView::new("Hello!"));
|
||||
/// ```
|
||||
pub fn new<S: ToVec2, V: View + 'static>(size: S, view: V) -> Self {
|
||||
BoxView {
|
||||
|
@ -21,7 +21,8 @@ enum Focus {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let dialog = Dialog::new(TextView::new("Hello!")).button("Ok", |s,_| s.quit());
|
||||
/// # use cursive::view::{Dialog,TextView};
|
||||
/// let dialog = Dialog::new(TextView::new("Hello!")).button("Ok", |s| s.quit());
|
||||
/// ```
|
||||
pub struct Dialog {
|
||||
title: String,
|
||||
|
@ -33,6 +33,7 @@ pub use self::id_view::IdView;
|
||||
pub use self::shadow_view::ShadowView;
|
||||
pub use self::edit_view::EditView;
|
||||
pub use self::select_view::SelectView;
|
||||
pub use self::scroll::ScrollBase;
|
||||
|
||||
use event::{Event,EventResult};
|
||||
use vec::{Vec2,ToVec2};
|
||||
|
@ -86,6 +86,12 @@ impl ScrollBase {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::view::ScrollBase;
|
||||
/// # use cursive::printer::Printer;
|
||||
/// # let scrollbase = ScrollBase::new();
|
||||
/// # let printer = Printer::new((5,1));
|
||||
/// # let printer = &printer;
|
||||
/// let lines = ["Line 1", "Line number 2"];
|
||||
/// scrollbase.draw(printer, |printer, i| {
|
||||
/// printer.print((0,0), lines[i]);
|
||||
/// });
|
||||
|
@ -77,26 +77,33 @@ impl <T: ViewWrapper> View for T {
|
||||
///
|
||||
/// If the wrapped view is in a box, just name it in the macro:
|
||||
///
|
||||
/// ```
|
||||
/// ```rust
|
||||
/// # #[macro_use] extern crate cursive;
|
||||
/// # use cursive::view::{View,ViewWrapper};
|
||||
/// struct BoxFooView {
|
||||
/// content: Box<View>,
|
||||
/// }
|
||||
///
|
||||
/// impl ViewWrapper for FooView {
|
||||
/// impl ViewWrapper for BoxFooView {
|
||||
/// wrap_impl!(self.content);
|
||||
/// }
|
||||
///
|
||||
/// # fn main() { }
|
||||
/// ```
|
||||
///
|
||||
/// If the content is directly a view, reference it:
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use] extern crate cursive;
|
||||
/// # use cursive::view::{View,ViewWrapper};
|
||||
/// struct FooView<T: View> {
|
||||
/// view: T,
|
||||
/// }
|
||||
///
|
||||
/// impl <T> ViewWrapper for FooView<T> {
|
||||
/// impl <T: View> ViewWrapper for FooView<T> {
|
||||
/// wrap_impl!(&self.view);
|
||||
/// }
|
||||
/// # fn main() { }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! wrap_impl {
|
||||
@ -121,3 +128,4 @@ macro_rules! wrap_impl {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user