65 releases

0.21.1 Aug 3, 2024
0.20.0 Sep 9, 2022
0.19.0 Jul 22, 2022
0.17.0 Jan 10, 2022
0.1.1 Jul 21, 2016

#22 in Command-line interface

Download history 2840/week @ 2024-07-31 2987/week @ 2024-08-07 3037/week @ 2024-08-14 3001/week @ 2024-08-21 2772/week @ 2024-08-28 2814/week @ 2024-09-04 2898/week @ 2024-09-11 3050/week @ 2024-09-18 4101/week @ 2024-09-25 3327/week @ 2024-10-02 2551/week @ 2024-10-09 3349/week @ 2024-10-16 3138/week @ 2024-10-23 3267/week @ 2024-10-30 2442/week @ 2024-11-06 1633/week @ 2024-11-13

11,120 downloads per month
Used in 166 crates (147 directly)

MIT license

1MB
22K SLoC

Cursive

crates.io Rust MIT licensed Gitter chat

Cursive is a TUI (Text User Interface) library for rust. It uses the crossterm backend by default, but other backends are available.

It allows you to build rich user interfaces for terminal applications.

Documentation

It is designed to be safe and easy to use:

[dependencies]
cursive = "0.21"

Or to use the latest git version:

[dependencies]
cursive = { git = "https://github.com/gyscos/cursive" }
use cursive::views::{Dialog, TextView};

fn main() {
    // Creates the cursive root - required for every application.
    let mut siv = cursive::default();

    // Creates a dialog with a single "Quit" button
    siv.add_layer(Dialog::around(TextView::new("Hello Dialog!"))
                         .title("Cursive")
                         .button("Quit", |s| s.quit()));

    // Starts the event loop.
    siv.run();
}

Cursive dialog example

Check out the other examples to get these results, and more:

lorem.rs example menubar.rs example select.rs example mines example theme_manual.rs example syntect example

(Colors may depend on your terminal configuration.)

Tutorials

These tutorials may help you get started with cursive:

Third-party views

Here are a few crates implementing new views for you to use:

Showcases

Here are some cool applications using cursive:

  • RustyChat: Chat client made using Rust and Cursive.
  • checkline: Checkbox line picker from stdin to stdout.
  • clock-cli: A clock with stopwatch and countdown timer functionalities.
  • fui: Add CLI & form interface to your program.
  • game2048-rs: a tui game2048 using Rust and cursive.
  • git-branchless: Branchless workflow for Git.
  • grin-tui: Minimal implementation of the MimbleWimble protocol.
  • kakikun: A paint and ASCII art application for the terminal.
  • launchk: Manage launchd agents and daemons on macOS.
  • markline: Marker-based line picker from stdin to stdout.
  • mythra: CLI to search for music.
  • ncspot: Cross-platform ncurses Spotify client.
  • rbmenu-tui: A TUI for bookmark management.
  • retris: A simple implementation of the classic tetris game.
  • ripasso: A simple password manager written in Rust.
  • rusty-man: Browse rustdoc documentation.
  • saci-rs: Simple API Client Interface.
  • so: A terminal interface for Stack Overflow.
  • sudoku-tui: Play sudoku on the command line.
  • tap: An audio player for the terminal with fuzzy finder.
  • ttyloop: Clone of the mobile game Loop.
  • wiki-tui: A simple and easy to use Wikipedia Text User Interface

Goals

  • Ease of use. Simple apps should be simple. Complex apps should be manageable.
  • Linux TTY Compatibility. Colors may suffer, and UTF-8 may be too much, but most features must work properly on a Linux TTY.
  • Flexibility. This library should be able to handle simple UI scripts, complex real-time applications, or even games.
    • In particular, it tries to have enough features to recreate these kind of tools:

Compatibility

First off, terminals are messy. A small set of features is standard, but beyond that, almost every terminal has its own implementation.

Output

  • Colors: the basic 8-colors palette should be broadly supported. User-defined colors is not supported in the raw linux TTY, but should work in most terminals, although it's still kinda experimental.
  • UTF-8: Currently Cursive really expects a UTF-8 locale. It may eventually get patched to support window borders on other locales, but it's not a priority. There is initial support for wide characters. RTL support is planned, but still very early.

Input

  • The key_codes example can be a useful tool to see how the library reacts to various key presses.
  • Keep in mind that if the terminal has shortcuts registered, they probably won't be transmitted to the app.
  • UTF-8 input should work fine in a unicode-enabled terminal emulator, but raw linux TTY may be more capricious.

Contributing

Alternatives

See also ratatui - and a small comparison page.

Dependencies

~6–17MB
~220K SLoC