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
Cursiveobject. 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§
- align
- Tools to control view alignment.
- backend
- Define the backend trait for actual terminal interaction.
- backends
- Define backends using common libraries.
- buffer
- Output buffer
- builder
- Build views from configuration.
- direction
- Direction-related structures.
- event
- User-input events and their effects.
- logger
- Logging utilities.
- menu
- Build menu trees.
- reexports
- Re-export crates used in the public API
- style
- Handle colors and styles in the UI.
- theme
- Theming support for a consistent UI.
- traits
- Commonly used traits bundled for easy import.
- utils
- Toolbox to make text layout easier.
- vec
- Points on the 2D character grid.
- view
- Base elements required to build views.
- views
- Various views to use when creating the layout.
Macros§
- fn_
blueprint - Define a macro for a variable builder.
- immut1
- Macro to wrap a
FnMutwith 1 argument into aFn. - immut2
- Macro to wrap a
FnMutwith 2 arguments into aFn. - immut3
- Macro to wrap a
FnMutwith 3 arguments into aFn. - impl_
enabled - A macro to help with creating toggleable views.
- impl_
scroller - Implements the
Scrollertrait for any type. - inner_
getters - Convenient macro to implement the getters for inner
ViewinViewWrapper. - manual_
blueprint - Define a blueprint to manually build this view from a config file.
- once1
- Macro to wrap a
FnOncewith 1 argument into aFnMut. - submit
- Enter an element into the plugin registry corresponding to its type.
- wrap_
impl - Convenient macro to implement the
ViewWrappertrait.
Structs§
- Cursive
- Central part of the cursive library.
- Cursive
Runnable - A runnable wrapper around
Cursive, bundling the backend initializer. - Cursive
Runner - Event loop runner for a cursive instance.
- Dump
- Represents a dump of everything from a
Cursiveinstance. - Printer
- Convenient interface to draw on a subset of the screen.
- Rect
- A non-empty rectangle on the 2D grid.
- XY
- A generic structure with a value for each axis.
Traits§
- Cursive
Ext - Extension trait for the
Cursiveroot to simplify initialization. - View
- Main trait defining a view behaviour.
- With
- Generic trait to enable chainable API
Functions§
- crossterm
crossterm-backend - Creates a new Cursive root using a crossterm backend.
- default
- Creates a new Cursive root using one of the enabled backends.
- dummy
- Creates a new Cursive root using a dummy backend.
- pancurses
pancurses-backend - Creates a new Cursive root using a pancurses backend.
- termion
termion-backend - Creates a new Cursive root using a termion backend.
Type Aliases§
- CbSink
- Convenient alias to the result of
Cursive::cb_sink. - Screen
Id - Identifies a screen in the cursive root.
- Vec2
- Simple 2D size, in cells.
Attribute Macros§
- blueprint
- Defines a blueprint for creating a view from config.
- callback_
helpers - Generate two helper functions to help working with cursive blueprints.