Skip to content

CortexLM/cTUI

Repository files navigation

cTUI

A high-performance TUI framework for Rust with React-style declarative components

Crate Repo Docs License CI

cTUI Website · Docs · Examples · Changelog · Contributing · Report a Bug · Request a Feature

cTUI (see-too-eye) is a Rust crate for building terminal user interfaces with a declarative, component-based approach. It brings modern frontend paradigms to the terminal, making it easy to create responsive, animated, and performant TUIs.

Features

  • Layer System - Z-index based layering for proper render ordering. Widgets can specify z_index() to control which elements appear on top.
  • Event Batching - Efficiently batch and process terminal events. Reduces overhead by coalescing rapid input sequences.
  • Component Pooling - Reuse component instances to minimize allocations and improve performance in frequently updated UIs.
  • WASM Backend - Compile to WebAssembly for browser-based terminals. Run your TUI in the browser with full feature parity.
  • Float Colors - Color32 type for high-precision color manipulation (0.0-1.0 range). Enable with the float-colors feature.
  • React-style Components - Declarative components with hooks (use_state, use_effect) for familiar state management.

Quickstart

Add cTUI to your project:

```shell cargo add ctui ```

Here's a minimal counter application:

```rust use ctui::{component, App, Component, Terminal}; use ctui::hooks::{use_state, use_effect};

#[component] fn Counter() -> impl Component { let (count, set_count) = use_state(0);

use_effect(move || {
    println!("Count: {}", count);
}, [count]);

Column::new()
    .child(Text::new(&format!("Count: {}", count)))
    .child(
        Row::new()
            .child(Button::new("-").on_click(move || set_count(count - 1)))
            .child(Button::new("+").on_click(move || set_count(count + 1)))
    )

}

#[tokio::main] async fn main() -> Result<(), Box> { let mut terminal = Terminal::new()?; let app = App::new(Counter {}); terminal.run(app).await } ```

Documentation

Templates

Get started quickly with project templates:

```shell cargo install ctui-cli ctui new my-app --template counter ```

Available templates:

  • `basic` - Minimal hello world application
  • `counter` - Counter app with state management
  • `todo-app` - Full CRUD todo application

Built with cTUI

Built with cTUI

Building something with cTUI? Add a badge to your README:

```md Built with cTUI ```

Alternatives

If cTUI doesn't fit your needs, consider these alternatives:

  • ratatui - Imperative TUI library with excellent widget ecosystem
  • cursive - ncurses-based TUI library
  • iocraft - Declarative TUI library with React-like API

Contributing

We welcome contributions! Whether you're fixing a bug, adding a feature, or improving documentation, your help makes cTUI better.

Please read the Contributing Guidelines before submitting a pull request. Key points:

License

Licensed under either of

at your option.

Acknowledgments

cTUI draws inspiration from several projects:

  • ratatui for pushing the Rust TUI ecosystem forward
  • React for pioneering the declarative component model
  • The Rust community for creating amazing tools and libraries

Built with care by the CortexLM team.

About

cTUI

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages