Demo Rust Cursive crate for terminal user interface (TUI)

Overview

Demo Rust Cursive

Demonstration of the Rust programming language and Cursvie crate for terminal user interface (TUI).

Setup

Create:

cargo new demo

Add crate:

[dependencies]
cursive = "*"

You need a Cursive backend installed, such as ncurses, pancurses, etc.

Examples

  • Run: Create the cursive root and run it; press ctrl-c to quit.

  • add_global_callback: Add a global callback so the user can press the escape key to quit.

Views

  • TextView: Show a TextView that shows the text "Hello World".

  • TextView get_shared_content Get a text view shared content reference, to do content mutation.

  • Dialog: Show a Dialog info box with a message and a default "Ok" button.

  • SelectView: Show a SelectView with items to pick, then quit.

  • ViewWrapper: Implement the ViewWrapper trait to wrap a view and intercept events.

Layouts

Clickables

  • Button: Show a button that the user can click to quit.

  • Checkbox: Show a Checkbox; press space or enter to toggle.

  • RadioGroup & RadioButton:: Show a RadioGroup and RadioButton items using a LinearLayout.

More

Themes

Edges

Tips

Convert TextView content to a &str:

main() {
    let text_view = cursive::views::TextView::new("Hello World");
    let s: &str = text_view.get_content().source();
}

Backends

Cursive can use various backends. We prefer to use the Termion backend. Discussion below.

Cursive will choose the backend to use, with this priority order:

  • blt-backend

  • termion-backend: pure-Rust Unix-specific backend

  • crossterm-backend: pure-Rust cross-platform backend

  • pancurses-backend

  • ncurses-backend: default on Unix

  • run_dummy

ncurses considerations

Discussion from source:

  • The ncurses crate is wildly unsound. It simply wraps calls to C functions in Rust functions and declares them safe, with no validation whatsoever. It has format string vulnerabilities, returns invalid UTF-8 in &str, and so much other unsoundness that you can cause pretty much arbitrary memory corruption. It is also unmaintained. See Tracker: All unsafe blocks must be removed and then re-added one by one after careful verification of actual safety.

  • The pancurses crate depends on ncurses and inherits the issues.

  • One of the reasons ncurses still the default backend is the input it supports: things like Ctrl+F1, Ctrl+Insert are currently working on the ncurses backend. Last time I quickly surveyed the other backends, none of them were returning enough information to implement that (even if it's raw input code from the terminal to be parsed in cursive itself). It's not critical to support these modifiers, but I was a bit sad having to cut features.

Crossterm discussion

Does Crossterm work on Apple macOS with M1/M2/ARM/AARCH?

  • Crossterm seems cause unresponsive terminals on my system, which is macOS Ventura 13.0 on a MacBook Pro with Apple M1 Max.

  • I reported the issue to the GitHub repositories for Cursive and for Crossterm.

BearLibTerminal discussion

Is BearLibTerminal maintained or not?

  • The BearLibTerminal GitHub repository shows the last update 3 years ago.

  • The BearLibTerminal GitHub installation instructions say to use pip install bearlibterminal. But on my system, the instructions don't work. The errors are: "ERROR: Could not find a version that satisfies the requirement bearlibterminal (from versions: none)" and "ERROR: No matching distribution found for bearlibterminal".

  • The BearLibTerminal example in this repo is examples/blt_terminal.rs. But on my system, the example doesn't work. The errors include: "note: ld: library not found for -lBearLibTerminal" and "clang: error: linker command failed with exit code 1 (use -v to see invocation)".

You might also like...
A cross platform minimalistic text user interface
A cross platform minimalistic text user interface

titik Titik is a crossplatform TUI widget library with the goal of being able to interact intuitively on these widgets. It uses crossterm as the under

Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.
Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.

Leetcode TUI Use Leetcode in your terminal. Why this TUI: My motivation for creating leetcode-tui stemmed from my preference for tools that are lightw

A tui to test regexes on the rust regex crate

regex-tui Structure src/ ├── app.rs - holds the states and renders the widgets ├── event.rs - handles the terminal events (key press, mouse cl

An easy-to-use TUI crate for Rust, based off of the Elm architecture.

Rustea An easy-to-use TUI crate for Rust, based off of the Elm architecture. This is a re-implementation of Go's Tea, created by TJ Holowaychuk. Featu

TUI for crate management like lazydocker and lazynpm
TUI for crate management like lazydocker and lazynpm

TUI for crate management like lazydocker and lazynpm. Shouldve named it as lazycargo but lazycrates sounded good at that time.

Build terminal user interfaces and dashboards using Rust
Build terminal user interfaces and dashboards using Rust

tui-rs tui-rs is a Rust library to build rich terminal user interfaces and dashboards. It is heavily inspired by the Javascript library blessed-contri

Github user information on terminal :D
Github user information on terminal :D

octofetch Use this if youre too lazy to open github lol Installation Local install with cargo Run cargo install --git https://github.com/azur1s/octofe

A Rust crate for parsing Windows user minidumps.
A Rust crate for parsing Windows user minidumps.

udmp-parser-rs: A Rust crate for parsing Windows user minidumps This is a cross-platform crate that parses Windows user minidump dumps that you can ge

Low-level Rust library for implementing terminal command line interface, like in embedded systems.

Terminal CLI Need to build an interactive command prompt, with commands, properties and with full autocomplete? This is for you. Example, output only

Owner
Joel Parker Henderson
Software developer. Technology consultant. Creator of GitAlias.com, NumCommand.com, SixArm.com, and many open source projects.
Joel Parker Henderson
OSINT from your favorite services in a friendly terminal user interface

osintui Open Source Intelligence Terminal User Interface Report Bug · Request Feature Installation First, install Rust (using the recommended rustup i

Will Sheldon 639 Jan 4, 2023
Terminal User Interface to help debugging programs written for Triton VM.

Triton TUI Terminal User Interface to run and debug programs written for Triton VM. Getting Started Triton TUI tries to be helpful. ?? List possible (

Triton VM 4 May 7, 2024
A template for bootstrapping a Rust TUI application with tui-rs & crossterm

rust-tui-template A template for bootstrapping a Rust TUI application with tui-rs & crossterm. tui-rs The library is based on the principle of immedia

Orhun Parmaksız 72 Dec 31, 2022
A user-friendly TUI client for Matrix written in Rust!

Konoha A user-friendly TUI client for Matrix written in Rust! Notice: The client is currently not usable and is only hosted on GitHub for version cont

L3af 9 Jan 5, 2022
A user-friendly TUI for secure file transfers, with arrow-key and VIM-style navigation

gsftp SFTP with an interactive text-based user interface (TUI). Transfer files through an encrypted connection with a visual interface, so you can see

Ben Jiron 3 Jul 7, 2022
A user-friendly, lightweight TUI for disk imaging

Caligula Burning Tool Caligula is a user-friendly, lightweight TUI for imaging disks. $ caligula burn -h Burn an image to a disk Usage: caligula burn

Astrid Yu 25 Mar 26, 2023
TUI interface for LLMs written in Rust 🔥

Tenere TUI interface for LLMs written in Rust ?? Demo ?? Supported LLMs Only ChatGPT is supported for the moment. But I'm planning to support more mod

BADR 22 Apr 22, 2023
A Text User Interface library for the Rust programming language

Cursive Cursive is a TUI (Text User Interface) library for rust. It uses ncurses by default, but other backends are available. It allows you to build

Alexandre Bury 3.3k Jan 9, 2023
A Text User Interface library for the Rust programming language

Cursive Cursive is a TUI (Text User Interface) library for rust. It uses ncurses by default, but other backends are available. It allows you to build

Alexandre Bury 3.3k Jan 3, 2023
ChatGPT-rs is a lightweight ChatGPT client with a graphical user interface, written in Rust

ChatGPT-rs is a lightweight ChatGPT client with a graphical user interface, written in Rust. It allows you to chat with OpenAI's GPT models through a simple and intuitive interface.

null 7 Apr 2, 2023