#web-apps #ratatui #applications #key-events #cell #terminal-themed

bin+lib ratzilla

Build terminal-themed web applications with Ratatui and WebAssembly

5 releases

new 0.0.0-alpha.4 Jan 20, 2025
0.0.0-alpha.3 Jan 17, 2025
0.0.0-alpha.2 Jan 15, 2025
0.0.0-alpha.0 Jan 9, 2025

#143 in WebAssembly

Download history 113/week @ 2025-01-06 331/week @ 2025-01-13

444 downloads per month

MIT/Apache

32KB
785 lines

Ratzilla

Build terminal-themed web applications with Rust and WebAssembly. Powered by Ratatui.

Quickstart

Add Ratzilla as a dependency in your Cargo.toml:

cargo add ratzilla

Here is a minimal example:

use std::cell::RefCell;
use std::io;
use std::rc::Rc;

use ratzilla::event::KeyCode;
use ratzilla::ratatui::{
    layout::Alignment,
    style::Color,
    widgets::{Block, Paragraph},
    Terminal,
};
use ratzilla::{DomBackend, RenderOnWeb};

fn main() -> io::Result<()> {
    let counter = Rc::new(RefCell::new(0));
    let backend = DomBackend::new()?;
    let terminal = Terminal::new(backend)?;

    terminal.on_key_event({
        let counter_cloned = counter.clone();
        move |key_event| {
            if key_event.code == KeyCode::Char(' ') {
                let mut counter = counter_cloned.borrow_mut();
                *counter += 1;
            }
        }
    });

    terminal.render_on_web(move |f| {
        let counter = counter.borrow();
        f.render_widget(
            Paragraph::new(format!("Count: {counter}"))
                .alignment(Alignment::Center)
                .block(
                    Block::bordered()
                        .title("Ratzilla")
                        .title_alignment(Alignment::Center)
                        .border_style(Color::Yellow),
                ),
            f.area(),
        );
    });

    Ok(())
}

Ratzilla uses trunk to build and serve the web application.

Install trunk with:

cargo install --locked trunk

Then serve it on your browser:

trunk serve

Now go to http://localhost:8080 and keep cooking!

Dependencies

~15MB
~251K SLoC