[][src]Struct cursive::CursiveRunnable

pub struct CursiveRunnable { /* fields omitted */ }

A runnable wrapper around Cursive, bundling the backend initializer.

This struct embeds both Cursive and a backend-initializer (FnMut() -> Result<dyn Backend>), to provide a simple .run() method.

This lets you pick the backend when creating the Cursive root, rather than when running it.

It implements DerefMut<Target=Cursive>, so you can use it just like a regular Cursive object.

Implementations

impl CursiveRunnable[src]

pub fn new<E, F>(mut backend_init: F) -> Self where
    E: Error + 'static,
    F: FnMut() -> Result<Box<dyn Backend>, E> + 'static, 
[src]

Creates a new Cursive wrapper, using the given backend.

pub fn run(&mut self)[src]

Runs the event loop with the registered backend initializer.

Panics

If the backend initialization fails.

pub fn try_run(&mut self) -> Result<(), Box<dyn Error>>[src]

Runs the event loop with the registered backend initializer.

pub fn try_runner(
    &mut self
) -> Result<CursiveRunner<&mut Cursive>, Box<dyn Error>>
[src]

Gets a runner with the registered backend.

Used to manually control the event loop. In most cases, running run() will be easier.

The runner will borrow self; when dropped, it will clear out the terminal, and the cursive instance will be ready for another run if needed.

pub fn runner(&mut self) -> CursiveRunner<&mut Cursive>[src]

Gets a runner with the registered backend.

Panics

If the backend initialization fails.

pub fn try_into_runner(
    mut self: Self
) -> Result<CursiveRunner<Self>, Box<dyn Error>>
[src]

Returns a new runner on the registered backend.

Used to manually control the event loop. In most cases, running run() will be easier.

The runner will embed self; when dropped, it will clear out the terminal, and the cursive instance will be dropped as well.

pub fn into_runner(self) -> CursiveRunner<Self>[src]

Returns a new runner on the registered backend.

Used to manually control the event loop. In most cases, running run() will be easier.

The runner will embed self; when dropped, it will clear out the terminal, and the cursive instance will be dropped as well.

Panics

If the backend initialization fails.

pub fn dummy() -> Self[src]

Creates a new Cursive wrapper using the dummy backend.

Nothing will actually be output when calling .run().

pub fn ncurses() -> Self[src]

Creates a new Cursive wrapper using the ncurses backend.

Requires the ncurses-backend feature.

pub fn default() -> Self[src]

Creates a new Cursive wrapper using one of the available backends.

Picks the first backend enabled from the list:

  • BearLibTerminal
  • Termion
  • Crossterm
  • Pancurses
  • Ncurses
  • Dummy

Methods from Deref<Target = Cursive>

pub fn screen_size(&self) -> XY<usize>[src]

Returns the screen size given in the last layout phase.

Note: this will return (0, 0) before the first layout phase.

pub fn set_user_data<T>(&mut self, user_data: T) where
    T: Any
[src]

Sets some data to be stored in Cursive.

It can later on be accessed with Cursive::user_data()

pub fn user_data<T>(&mut self) -> Option<&mut T> where
    T: Any
[src]

Attempts to access the user-provided data.

If some data was set previously with the same type, returns a reference to it.

If nothing was set or if the type is different, returns None.

pub fn take_user_data<T>(&mut self) -> Option<T> where
    T: Any
[src]

Attemps to take by value the current user-data.

If successful, this will replace the current user-data with the unit type ().

If the current user data is not of the requested type, None will be returned.

Examples

let mut siv = cursive_core::Cursive::new();

// Start with a simple `Vec<i32>` as user data.
siv.set_user_data(vec![1i32, 2, 3]);
assert_eq!(siv.user_data::<Vec<i32>>(), Some(&mut vec![1i32, 2, 3]));

// Let's mutate the data a bit.
siv.with_user_data(|numbers: &mut Vec<i32>| numbers.push(4));

// If mutable reference is not enough, we can take the data by value.
let data: Vec<i32> = siv.take_user_data().unwrap();
assert_eq!(data, vec![1i32, 2, 3, 4]);

// At this point the user data was removed and is no longer available.
assert_eq!(siv.user_data::<Vec<i32>>(), None);

pub fn with_user_data<F, T, R>(&mut self, f: F) -> Option<R> where
    F: FnOnce(&mut T) -> R,
    T: Any
[src]

Runs the given closure on the stored user data, if any.

If no user data was supplied, or if the type is different, nothing will be run.

Otherwise, the result will be returned.

pub fn show_debug_console(&mut self)[src]

Show the debug console.

Currently, this will show logs if logger::init() was called.

pub fn toggle_debug_console(&mut self)[src]

Show the debug console, or hide it if it's already visible.

Examples

siv.add_global_callback('~', Cursive::toggle_debug_console);

pub fn cb_sink(
    &self
) -> &Sender<Box<dyn FnOnce(&mut Cursive) + 'static + Send, Global>>
[src]

Returns a sink for asynchronous callbacks.

Returns the sender part of a channel, that allows to send callbacks to self from other threads.

Callbacks will be executed in the order of arrival on the next event cycle.

Notes

Callbacks need to be Send, which can be limiting in some cases.

In some case send_wrapper may help you work around that.

Examples

let mut siv = Cursive::new();

// quit() will be called during the next event cycle
siv.cb_sink().send(Box::new(|s| s.quit())).unwrap();

pub fn select_menubar(&mut self)[src]

Selects the menubar.

pub fn set_autohide_menu(&mut self, autohide: bool)[src]

Sets the menubar autohide feature.

  • When enabled (default), the menu is only visible when selected.
  • When disabled, the menu is always visible and reserves the top row.

pub fn menubar(&mut self) -> &mut Menubar[src]

Access the menu tree used by the menubar.

This allows to add menu items to the menubar.

Examples

let mut siv = Cursive::new();

siv.menubar()
    .add_subtree(
        "File",
        MenuTree::new()
            .leaf("New", |s| s.add_layer(Dialog::info("New file!")))
            .subtree(
                "Recent",
                MenuTree::new().with(|tree| {
                    for i in 1..100 {
                        tree.add_leaf(format!("Item {}", i), |_| ())
                    }
                }),
            )
            .delimiter()
            .with(|tree| {
                for i in 1..10 {
                    tree.add_leaf(format!("Option {}", i), |_| ());
                }
            })
            .delimiter()
            .leaf("Quit", |s| s.quit()),
    )
    .add_subtree(
        "Help",
        MenuTree::new()
            .subtree(
                "Help",
                MenuTree::new()
                    .leaf("General", |s| {
                        s.add_layer(Dialog::info("Help message!"))
                    })
                    .leaf("Online", |s| {
                        s.add_layer(Dialog::info("Online help?"))
                    }),
            )
            .leaf("About", |s| {
                s.add_layer(Dialog::info("Cursive v0.0.0"))
            }),
    );

siv.add_global_callback(event::Key::Esc, |s| s.select_menubar());

pub fn current_theme(&self) -> &Theme[src]

Returns the currently used theme.

pub fn set_theme(&mut self, theme: Theme)[src]

Sets the current theme.

pub fn update_theme(&mut self, f: impl FnOnce(&mut Theme))[src]

Updates the current theme.

pub fn clear(&mut self)[src]

Clears the screen.

Users rarely have to call this directly.

pub fn load_theme_file<P>(&mut self, filename: P) -> Result<(), Error> where
    P: AsRef<Path>, 
[src]

Loads a theme from the given file.

filename must point to a valid toml file.

Must have the toml feature enabled.

pub fn load_toml(&mut self, content: &str) -> Result<(), Error>[src]

Loads a theme from the given string content.

Content must be valid toml.

Must have the toml feature enabled.

pub fn set_fps(&mut self, fps: u32)[src]

Sets the refresh rate, in frames per second.

Note that the actual frequency is not guaranteed.

Between 0 and 30. Call with fps = 0 to disable (default value).

pub fn set_autorefresh(&mut self, autorefresh: bool)[src]

Enables or disables automatic refresh of the screen.

This is a shortcut to call set_fps with 30 or 0 depending on autorefresh.

pub fn fps(&self) -> Option<NonZeroU32>[src]

Returns the current refresh rate, if any.

Returns None if no auto-refresh is set. Otherwise, returns the rate in frames per second.

pub fn screen(&self) -> &StackView[src]

Returns a reference to the currently active screen.

pub fn screen_mut(&mut self) -> &mut StackView[src]

Returns a mutable reference to the currently active screen.

pub fn active_screen(&self) -> usize[src]

Returns the id of the currently active screen.

pub fn add_screen(&mut self) -> usize[src]

Adds a new screen, and returns its ID.

pub fn add_active_screen(&mut self) -> usize[src]

Convenient method to create a new screen, and set it as active.

pub fn set_screen(&mut self, screen_id: usize)[src]

Sets the active screen. Panics if no such screen exist.

pub fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R> where
    F: FnOnce(&mut V) -> R,
    V: View
[src]

Tries to find the view pointed to by the given selector.

Runs a closure on the view once it's found, and return the result.

If the view is not found, or if it is not of the asked type, returns None.

Examples

let mut siv = Cursive::new();

siv.add_layer(views::TextView::new("Text #1").with_name("text"));

siv.add_global_callback('p', |s| {
    s.call_on(
        &view::Selector::Name("text"),
        |view: &mut views::TextView| {
            view.set_content("Text #2");
        },
    );
});

pub fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R> where
    F: FnOnce(&mut V) -> R,
    V: View
[src]

Tries to find the view identified by the given id.

Convenient method to use call_on with a view::Selector::Id.

Examples

let mut siv = Cursive::new();

siv.add_layer(views::TextView::new("Text #1").with_name("text"));

siv.add_global_callback('p', |s| {
    s.call_on_name("text", |view: &mut views::TextView| {
        view.set_content("Text #2");
    });
});

pub fn call_on_all_named<V, F>(&mut self, name: &str, callback: F) where
    F: FnMut(&mut V),
    V: View
[src]

Call the given closure on all views with the given name and the correct type.

pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R> where
    F: FnOnce(&mut V) -> R,
    V: View
[src]

👎 Deprecated:

call_on_id is being renamed to call_on_name

Same as call_on_name.

pub fn find_name<V>(
    &mut self,
    id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
    V: View
[src]

Convenient method to find a view wrapped in NamedView.

This looks for a NamedView<V> with the given name, and return a ViewRef to the wrapped view. The ViewRef implements DerefMut<Target=T>, so you can treat it just like a &mut T.

Examples

use cursive_core::traits::Identifiable;

siv.add_layer(TextView::new("foo").with_name("id"));

// Could be called in a callback
let mut view: ViewRef<TextView> = siv.find_name("id").unwrap();
view.set_content("bar");

Note that you must specify the exact type for the view you're after; for example, using the wrong item type in a SelectView will not find anything:

use cursive_core::traits::Identifiable;

let select = SelectView::new().item("zero", 0u32).item("one", 1u32);
siv.add_layer(select.with_name("select"));

// Specifying a wrong type will not return anything.
assert!(siv.find_name::<SelectView<String>>("select").is_none());

// Omitting the type will use the default type, in this case `String`.
assert!(siv.find_name::<SelectView>("select").is_none());

// But with the correct type, it works fine.
assert!(siv.find_name::<SelectView<u32>>("select").is_some());

pub fn find_id<V>(
    &mut self,
    id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
    V: View
[src]

👎 Deprecated:

find_id is being renamed to find_name

Same as find_name.

pub fn focus_name(&mut self, name: &str) -> Result<(), ViewNotFound>[src]

Moves the focus to the view identified by name.

Convenient method to call focus with a view::Selector::Name.

pub fn focus_id(&mut self, id: &str) -> Result<(), ViewNotFound>[src]

👎 Deprecated:

focus_id is being renamed to focus_name

Same as focus_name.

pub fn focus(&mut self, sel: &Selector<'_>) -> Result<(), ViewNotFound>[src]

Moves the focus to the view identified by sel.

pub fn add_global_callback<F, E>(&mut self, event: E, cb: F) where
    F: FnMut(&mut Cursive) + 'static,
    E: Into<Event>, 
[src]

Adds a global callback.

Will be triggered on the given key press when no view catches it.

Examples

let mut siv = Cursive::new();

siv.add_global_callback('q', |s| s.quit());

pub fn set_on_post_event<F, E>(&mut self, trigger: E, cb: F) where
    F: FnMut(&mut Cursive) + 'static,
    E: Into<EventTrigger>, 
[src]

Registers a callback for ignored events.

This is the same as add_global_callback, but can register any EventTrigger.

pub fn set_on_pre_event<F, E>(&mut self, trigger: E, cb: F) where
    F: FnMut(&mut Cursive) + 'static,
    E: Into<EventTrigger>, 
[src]

Registers a priotity callback.

If an event matches the given trigger, it will not be sent to the view tree and will go to the given callback instead.

Note that regular "post-event" callbacks will also be skipped for these events.

pub fn set_on_pre_event_inner<E, F>(&mut self, trigger: E, cb: F) where
    F: Fn(&Event) -> Option<EventResult> + 'static,
    E: Into<EventTrigger>, 
[src]

Registers an inner priority callback.

See OnEventView for more information.

pub fn set_on_event_inner<E, F>(&mut self, trigger: E, cb: F) where
    F: Fn(&Event) -> Option<EventResult> + 'static,
    E: Into<EventTrigger>, 
[src]

Registers an inner callback.

See OnEventView for more information.

pub fn set_global_callback<F, E>(&mut self, event: E, cb: F) where
    F: FnMut(&mut Cursive) + 'static,
    E: Into<Event>, 
[src]

Sets the only global callback for the given event.

Any other callback for this event will be removed.

See also Cursive::add_global_callback.

pub fn debug_name(&mut self, name: &str) -> Option<&'static str>[src]

Fetches the type name of a view in the tree.

pub fn clear_global_callbacks<E>(&mut self, event: E) where
    E: Into<Event>, 
[src]

Removes any callback tied to the given event.

Examples

use cursive_core::Cursive;
let mut siv = Cursive::new();

siv.add_global_callback('q', |s| s.quit());
siv.clear_global_callbacks('q');

pub fn reset_default_callbacks(&mut self)[src]

This resets the default callbacks.

Currently this mostly includes exiting on Ctrl-C.

pub fn add_layer<T>(&mut self, view: T) where
    T: IntoBoxedView
[src]

Add a layer to the current screen.

Examples

use cursive_core::{views, Cursive};
let mut siv = Cursive::new();

siv.add_layer(views::TextView::new("Hello world!"));

pub fn add_fullscreen_layer<T>(&mut self, view: T) where
    T: IntoBoxedView
[src]

Adds a new full-screen layer to the current screen.

Fullscreen layers have no shadow.

pub fn pop_layer(&mut self) -> Option<Box<dyn View + 'static, Global>>[src]

Convenient method to remove a layer from the current screen.

pub fn reposition_layer(&mut self, layer: LayerPosition, position: XY<Offset>)[src]

Convenient stub forwarding layer repositioning.

pub fn on_event(&mut self, event: Event)[src]

Processes an event.

  • If the menubar is active, it will be handled the event.
  • The view tree will be handled the event.
  • If ignored, global_callbacks will be checked for this event.

pub fn is_running(&self) -> bool[src]

Returns true until quit(&mut self) is called.

pub fn run_dummy(&mut self)[src]

Runs a dummy event loop.

Initializes a dummy backend for the event loop.

pub fn runner(
    &mut self,
    backend: Box<dyn Backend + 'static, Global>
) -> CursiveRunner<&mut Cursive>
[src]

Returns a new runner on the given backend.

Used to manually control the event loop. In most cases, running Cursive::run_with will be easier.

The runner will borrow self; when dropped, it will clear out the terminal, and the cursive instance will be ready for another run if needed.

pub fn run_with<F>(&mut self, backend_init: F) where
    F: FnOnce() -> Box<dyn Backend + 'static, Global>, 
[src]

Initialize the backend and runs the event loop.

Used for infallible backend initializers.

pub fn try_run_with<E, F>(&mut self, backend_init: F) -> Result<(), E> where
    F: FnOnce() -> Result<Box<dyn Backend + 'static, Global>, E>, 
[src]

Initialize the backend and runs the event loop.

Returns an error if initializing the backend fails.

pub fn quit(&mut self)[src]

Stops the event loop.

pub fn noop(&mut self)[src]

Does not do anything.

pub fn dump(&mut self) -> Dump[src]

Dump the current state of the Cursive root.

It will clear out this Cursive instance and save everything, including:

  • The view tree
  • Callbacks
  • Menubar
  • User data
  • Callback sink

After calling this, the cursive object will be as if newly created.

pub fn restore(&mut self, dump: Dump)[src]

Restores the state from a previous dump.

This will discard everything from this Cursive instance. In particular:

  • All current views will be dropped, replaced by the dump.
  • All callbacks will be replaced.
  • Menubar will be replaced.
  • User Data will be replaced.
  • The callback channel will be replaced - any previous call to cb_sink on this instance will be disconnected.

Trait Implementations

impl Deref for CursiveRunnable[src]

type Target = Cursive

The resulting type after dereferencing.

impl DerefMut for CursiveRunnable[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> With for T[src]