Crate cursive

source ·
Expand description

§Cursive

Cursive is a TUI library - it lets you easily build rich interfaces for use in a terminal.

§Getting started

  • Every application should start with a Cursive object. It is the main entry-point to the library.
  • A declarative phase then describes the structure of the UI by adding views and configuring their behaviours.
  • Finally, the event loop is started by calling Cursive::run.

§Examples

use cursive::views::TextView;
use cursive::{Cursive, CursiveExt};

let mut siv = Cursive::new();

siv.add_layer(TextView::new("Hello World!\nPress q to quit."));

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

siv.run();

§Views

Views are the main components of a cursive interface. The views module contains many views to use in your application; if you don’t find what you need, you may also implement the View trait and build your own.

§Callbacks

Cursive is callback-driven: it reacts to events generated by user input.

During the declarative phase, callbacks are set to trigger on specific events. These functions usually take an &mut Cursive argument, allowing them to modify the view tree at will.

§Debugging

The Cursive root initializes the terminal on creation, and does cleanups on drop. While it is alive, printing to the terminal will not work as expected, making debugging a bit harder.

One solution is to redirect stderr to a file when running the application, and log to it instead of stdout.

Or you can use gdb as usual.

§Themes

Cursive supports configuring the feels and looks of your application with custom themes and colors. For details see documentation of the cursive::theme module.

Modules§

  • Tools to control view alignment.
  • Define the backend trait for actual terminal interaction.
  • Define backends using common libraries.
  • Output buffer
  • Build views from configuration.
  • Direction-related structures.
  • User-input events and their effects.
  • Logging utilities.
  • Build menu trees.
  • Re-export crates used in the public API
  • Handle colors and styles in the UI.
  • Theming support for a consistent UI.
  • Commonly used traits bundled for easy import.
  • Toolbox to make text layout easier.
  • Points on the 2D character grid.
  • Base elements required to build views.
  • Various views to use when creating the layout.

Macros§

  • Define a macro for a variable builder.
  • Macro to wrap a FnMut with 1 argument into a Fn.
  • Macro to wrap a FnMut with 2 arguments into a Fn.
  • Macro to wrap a FnMut with 3 arguments into a Fn.
  • A macro to help with creating toggleable views.
  • Implements the Scroller trait for any type.
  • Convenient macro to implement the getters for inner View in ViewWrapper.
  • Define a blueprint to build this view from a config file.
  • Macro to wrap a FnOnce with 1 argument into a FnMut.
  • Enter an element into the plugin registry corresponding to its type.
  • Convenient macro to implement the ViewWrapper trait.

Structs§

  • Central part of the cursive library.
  • A runnable wrapper around Cursive, bundling the backend initializer.
  • Event loop runner for a cursive instance.
  • Represents a dump of everything from a Cursive instance.
  • Convenient interface to draw on a subset of the screen.
  • A non-empty rectangle on the 2D grid.
  • A generic structure with a value for each axis.

Traits§

  • Extension trait for the Cursive root to simplify initialization.
  • Main trait defining a view behaviour.
  • Generic trait to enable chainable API

Functions§

  • crosstermcrossterm-backend
    Creates a new Cursive root using a crossterm backend.
  • Creates a new Cursive root using one of the enabled backends.
  • Creates a new Cursive root using a dummy backend.
  • pancursespancurses-backend
    Creates a new Cursive root using a pancurses backend.
  • termiontermion-backend
    Creates a new Cursive root using a termion backend.

Type Aliases§

  • Convenient alias to the result of Cursive::cb_sink.
  • Identifies a screen in the cursive root.
  • Simple 2D size, in cells.

Attribute Macros§

  • Defines a blueprint for creating a view from config.
  • Generate two helper functions to help working with cursive blueprints.