Struct cursive::Cursive [] [src]

pub struct Cursive {
    // some fields omitted
}

Central part of the cursive library.

It initializes ncurses on creation and cleans up on drop. To use it, you should populate it with views, layouts and callbacks, then start the event loop with run().

It uses a list of screen, with one screen active at a time.

Methods

impl Cursive
[src]

Creates a new Cursive root, and initialize ncurses.

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.

Selects the menubar

Sets the menubar autohide_menubar feature.

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

Retrieve 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("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("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(Key::Esc, |s| s.select_menubar());

Returns the currently used theme

Sets the current theme.

Loads a theme from the given file.

filename must point to a valid toml file.

Loads a theme from the given string content.

Content must be valid toml.

Sets the refresh rate, in frames per second.

Regularly redraws everything, even when no input is given. Between 0 and 1000. Call with fps=0 to disable (default value).

Returns a reference to the currently active screen.

Returns a mutable reference to the currently active screen.

Adds a new screen, and returns its ID.

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

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

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

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

Examples

let mut siv = Cursive::new();

siv.add_layer(IdView::new("text", TextView::new("Text #1")));

siv.add_global_callback('p', |s| {
    s.find::<TextView>(&Selector::Id("text"))
     .unwrap()
     .set_content("Text #2");
});

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

Examples

let mut siv = Cursive::new();

siv.add_layer(IdView::new("text", TextView::new("Text #1")));

siv.add_global_callback('p', |s| {
    s.find_id::<TextView>("text")
     .unwrap()
     .set_content("Text #2");
});

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());

Convenient method to add a layer to the current screen.

Examples

let mut siv = Cursive::new();

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

Convenient method to remove a layer from the current screen.

Returns the size of the screen, in characters.

Runs the event loop.

It will wait for user input (key presses) and trigger callbacks accordingly.

Blocks until quit() is called.

Stops the event loop.

Trait Implementations

impl Default for Cursive
[src]

Returns the "default value" for a type. Read more

impl Drop for Cursive
[src]

A method called when the value goes out of scope. Read more