Crate tears

Crate tears 

Source
Expand description

§Tears - TUI Elm Architecture Runtime System

Tears is a TUI (Text User Interface) framework based on the Elm Architecture (TEA), built on top of ratatui. It provides a clean and type-safe way to build terminal applications using a functional, message-driven architecture.

§Architecture

The framework follows the Elm Architecture pattern:

  1. Model: Your application state
  2. Message: Events that can change the state
  3. Update: Function that processes messages and updates the model
  4. View: Function that renders the UI based on the current model
  5. Subscriptions: External event sources (keyboard, timers, etc.)
  6. Commands: Asynchronous operations that produce messages

§Core Components

§Example

use ratatui::Frame;
use tears::prelude::*;

#[derive(Debug)]
enum Message {
    Increment,
}

struct Counter {
    count: u32,
}

impl Application for Counter {
    type Message = Message;
    type Flags = ();

    fn new(_flags: ()) -> (Self, Command<Message>) {
        (Counter { count: 0 }, Command::none())
    }

    fn update(&mut self, msg: Message) -> Command<Message> {
        match msg {
            Message::Increment => {
                self.count += 1;
                Command::none()
            }
        }
    }

    fn view(&self, frame: &mut Frame<'_>) {
        // Render your UI here
    }

    fn subscriptions(&self) -> Vec<Subscription<Message>> {
        vec![]
    }
}

§Optional Features

Tears provides optional features that can be enabled in your Cargo.toml:

§WebSocket Support

  • ws: Enables WebSocket subscription support via subscription::websocket::WebSocket

Requires one of the following TLS features for secure connections (wss://):

  • native-tls: Uses the platform’s native TLS implementation
  • rustls: Uses rustls with ring crypto provider and native root certificates
  • rustls-tls-webpki-roots: Uses rustls with ring crypto provider and webpki root certificates

Example:

[dependencies]
tears = { version = "0.6", features = ["ws", "native-tls"] }

§Design Inspiration

This framework is inspired by iced 0.12, adapted for TUI applications.

Re-exports§

pub use application::Application;
pub use command::Action;
pub use command::Command;
pub use runtime::Runtime;
pub use subscription::Subscription;
pub use subscription::SubscriptionId;
pub use subscription::SubscriptionSource;

Modules§

application
Application trait and core types.
command
Commands for performing asynchronous side effects.
prelude
Prelude module for convenient imports.
runtime
Runtime for executing TUI applications.
subscription
Subscriptions for handling ongoing event sources.

Type Aliases§

BoxStream
An owned dynamically typed Stream for use in cases where you can’t statically type your result or need to add some indirection.