[][src]Crate cursive

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::{Cursive, CursiveExt};
use cursive::views::TextView;

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.

direction

Direction-related structures.

event

User-input events and their effects.

logger

Logging utilities

menu

Build menu trees.

theme

Handle colors and themes in the 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

immut1

Macro to wrap a FnMut with 1 argument into a Fn.

immut2

Macro to wrap a FnMut with 2 arguments into a Fn.

immut3

Macro to wrap a FnMut with 3 arguments into a Fn.

impl_enabled

A macro to help with creating toggleable views.

impl_scroller

Implements the Scroller trait for any type.

inner_getters

Convenient macro to implement the getters for inner View in ViewWrapper.

once1

Macro to wrap a FnOnce with 1 argument into a FnMut.

wrap_impl

Convenient macro to implement the ViewWrapper trait.

Structs

Cursive

Central part of the cursive library.

CursiveRunnable

A runnable wrapper around Cursive, bundling the backend initializer.

CursiveRunner

Event loop runner for a cursive instance.

Dump

Represents a dump of everything from a Cursive instance.

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

CursiveExt

Extension trait for the Cursive root to simplify initialization.

View

Main trait defining a view behaviour.

With

Generic trait to enable chainable API

Functions

default

Creates a new Cursive root using one of the enabled backends.

dummy

Creates a new Cursive root using a dummy backend.

ncurses

Creates a new Cursive root using a ncurses backend.

Type Definitions

CbSink

Convenient alias to the result of Cursive::cb_sink.

ScreenId

Identifies a screen in the cursive root.

Vec2

Simple 2D size, in cells.