webatui-ref

Reference implementation for webatui - Terminal UI that works in both terminal and browser

A library demonstrating how to build terminal UI applications with Ratatui that can run in both native terminals and web browsers via WebAssembly.

Rust License WASM Compatible


๐Ÿš€ Features

  • Terminal Support: Full ratatui-based terminal UI with crossterm
  • Web Support: WASM compilation ready (Yew components)
  • State Management: Unified state across platforms
  • Component System: Reusable UI widgets
  • Examples: Multiple working examples
  • Well Tested: Comprehensive test suite for both native and WASM

โšก Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/raibid-labs/webatui-ref.git
cd webatui-ref
 
# Install development tools (bacon, wasm-pack, etc.)
just install-deps

Running Examples

This is a library crate - run the examples to see it in action:

# List available examples
just list-examples
 
# Run an example
just example basic
just example dashboard
just example interactive
 
# Or use cargo directly
cargo run --example basic --features terminal

๐Ÿ“š Documentation

๐Ÿ—๏ธ Project Structure

webatui-ref/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ lib.rs           # Library entry point
โ”‚   โ”œโ”€โ”€ state.rs         # Core state (platform-independent)
โ”‚   โ”œโ”€โ”€ components/      # Terminal UI components
โ”‚   โ””โ”€โ”€ screens/         # Terminal UI screens
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic.rs         # Simple terminal UI
โ”‚   โ”œโ”€โ”€ dashboard.rs     # Dashboard with metrics
โ”‚   โ””โ”€โ”€ interactive.rs   # Interactive UI demo
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ integration_test.rs  # Native tests
โ”‚   โ””โ”€โ”€ wasm_tests.rs        # WASM-specific tests
โ”œโ”€โ”€ docs/                # Documentation
โ”œโ”€โ”€ .bacon/              # Bacon file watcher config
โ””โ”€โ”€ justfile             # Task automation

๐Ÿ› ๏ธ Development

Watch Mode

# Watch and rebuild
just watch
 
# Watch and run tests
just watch-test
 
# Watch specific example
just watch-example basic

Testing

# Run all tests
just test
 
# Test WASM compilation
just wasm-build
 
# Test in browser (requires ChromeDriver)
just wasm-test-browser

Building

# Build for terminal (native)
cargo build --features terminal
 
# Build for web (WASM)
just wasm-build
 
# Build release
cargo build --release --features terminal

๐Ÿ“ฆ Using as a Library

Add to your Cargo.toml:

[dependencies]
webatui-ref = { git = "https://github.com/raibid-labs/webatui-ref", features = ["terminal"] }

Example usage:

use webatui_ref::prelude::*;
 
fn main() -> anyhow::Result<()> {
    let mut state = AppState::default();
    state.update(Message::Navigate(Screen::Dashboard));
    assert_eq!(state.current_screen, Screen::Dashboard);
    Ok(())
}

๐ŸŽฏ Features

The crate uses feature flags for platform-specific dependencies:

  • terminal - Terminal UI support (ratatui, crossterm) - Default on native
  • web - Web/WASM support (yew, wasm-bindgen)
  • examples - Additional example features

๐Ÿ”ง Available Commands

Run just --list to see all available commands. Key commands:

CommandDescription
just list-examplesShow all examples
just example <name>Run specific example
just testRun all tests
just watchWatch and rebuild
just watch-testWatch and run tests
just wasm-buildBuild for WASM
just fmtFormat code
just lintRun clippy

Bacon (File Watcher)

The project uses bacon for file watching (Apple Silicon compatible):

bacon                # Build with watch
bacon test           # Test with watch
bacon example-basic  # Run example with watch
bacon wasm-check     # Check WASM compilation

See .bacon/bacon.toml for all configured jobs.

๐Ÿ“– Examples

Basic Example

Simple terminal UI demonstrating core functionality:

just example basic

Features: Text display, keyboard events, state updates

Dashboard Example

Comprehensive dashboard with real-time metrics:

just example dashboard

Features: Charts, gauges, tables, system monitoring

Interactive Example

Advanced interaction patterns:

just example interactive

Features: Text input, navigation, interactive widgets

๐Ÿงช Testing

Native Tests

cargo test --features terminal
  • 6 unit tests in src/lib.rs
  • 7 integration tests in tests/integration_test.rs
  • Component-specific tests

WASM Tests

# Build for WASM (verify compilation)
cargo build --target wasm32-unknown-unknown --lib --no-default-features
 
# Run WASM tests (requires wasm-pack)
wasm-pack test --node -- --lib --no-default-features

๐Ÿ–ฅ๏ธ Platform Support

Native Terminals

  • โœ… macOS (Intel & Apple Silicon)
  • โœ… Linux
  • โœ… Windows

Terminal Emulators

  • Alacritty
  • Kitty
  • iTerm2
  • WezTerm
  • Windows Terminal

Browsers (WASM)

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+

โš™๏ธ Technology Stack

Core Dependencies

[dependencies]
ratatui = "0.29"           # Terminal UI framework
crossterm = "0.28"         # Terminal handling (native only)
 
# WASM support (optional)
yew = { version = "0.21", optional = true }
wasm-bindgen = { version = "0.2", optional = true }
 
# State management
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
 
# Async runtime
tokio = { version = "1.42", features = ["sync", "macros"], default-features = false }

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: cargo test --features terminal
  5. Format code: cargo fmt
  6. Run lints: cargo clippy --features terminal
  7. Commit changes
  8. Submit a pull request

๐Ÿ“ License

Licensed under either of:

at your option.

๐Ÿ™ Acknowledgments

Built with:

๐Ÿ”— Resources

Documentation

Community


Built by Raibid Labs

Terminal applications that work everywhere