Cursive is a TUI (Text User Interface) library for rust. It is currently based on jeaye's ncurses-rs, but other backends are available.
It allows you to build rich user interfaces for terminal applications.
It is designed to be safe and easy to use:
toml
[dependencies]
cursive = "0.4"
Or to use the latest git version:
toml
[dependencies]
cursive = { git = "https://github.com/gyscos/Cursive" }
(You will also need ncurses installed - if it isn't already, check in your package manager. Make sure you install the ncursesw
version if available, for UTF-8 support.)
```rust,no_run extern crate cursive;
use cursive::Cursive; use cursive::views::{Dialog, TextView};
fn main() { // Creates the cursive root - required for every application. let mut siv = Cursive::new();
// 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();
} ```
Check out the other examples to get these results, and more:
(Colors may depend on your terminal configuration.)
These tutorials may help you get started with cursive:
First off, terminals are messy. A small set of features is standard, but beyond that, almost every terminal has its own implementation.
key_codes
example can be a useful tool to see how the library reacts to various key presses.Here is the support table for input keys. Tested terminals are mostly Gnome terminal and Linux TTY, xterm, and a few others now and then.
| | Key | Shift+Key | Ctrl+Key | Shift+Ctrl+Key | |--------------------------|:----:|:----------------------:|:--------------------------:|:---------------:| | Letters | All | All | All (except c,z,q,s,i,h,m) | None | | Numbers | All | All | None (can crash the app) | None | | Punctuation | All | All | None (can crash the app) | None | | Enter, Esc | All | None | None | None | | Left, Right arrow keys | All | VTE+Xterm | VTE+Xterm | VTE+Xterm | | Up, Down arrow keys | All | Xterm | VTE+Xterm | Xterm | | Ins | All | None (paste clipboard) | Xterm | None | | Del | All | VTE+Xterm | VTE+Xterm | VTE+Xterm | | Home, End | All | Xterm | Xterm | Xterm | | PageUp, PageDown | All | All | All | None | | Fn keys: F1-F4 | All | All except Konsole | Gnome+XTerm | Gnome+Xterm | | Fn keys: F5-F8 | All | All | All except TTY | All except TTY | | Fn keys: F9-F12 | All | All except TTY | All except TTY | All except TTY | | PrtScn, ScrollLock | None | None | None | None | | Window, Menu | None | None | None | None | | Ctrl, Shift, Alt (by themselves) | None | None | None | None |
You want to help? Thank you so much! Here are some ideas of things you could do:
key_codes
example on your favorite terminal, and report the results!