ratatui-reactive 0.6.0

A minimalistic framework for building TUI applications using fine-grained reactivity.
Documentation
use crate::{ReactiveApp, Runtime, init_mock_events, on_key_press};
use async_local_channel::spsc;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use ratatui::Terminal;
use ratatui::backend::TestBackend;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use sycamore_reactive::use_context;
use tokio::select;
use tokio::task::yield_now;

#[tokio::test(flavor = "local")]
async fn first_draw() {
    let app = ReactiveApp::new(move || |_: Rect, _: &mut Buffer| ());
    assert!(app.draw_requested().await);
    let backend = TestBackend::new(0, 0);
    let mut terminal = Terminal::new(backend).unwrap();
    terminal.draw(|frame| app.draw(frame)).unwrap();
    select! {
        biased;

        _ = app.draw_requested() => panic!("shouldn't request another draw call"),
        _= yield_now() => (),
    }
}

#[tokio::test(flavor = "local")]
async fn quit() {
    let (event_tx, event_rx) = spsc::channel();

    let app = ReactiveApp::new(move || {
        init_mock_events(event_rx.activate());
        let runtime = use_context::<Runtime>();

        on_key_press(move |key| {
            if let KeyCode::Char('q') = key.code {
                runtime.quit()
            }
        });

        move |_: Rect, _: &mut Buffer| ()
    });
    assert!(app.draw_requested().await);
    let backend = TestBackend::new(0, 0);
    let mut terminal = Terminal::new(backend).unwrap();
    terminal.draw(|frame| app.draw(frame)).unwrap();
    event_tx
        .send(Event::Key(KeyEvent::new(
            KeyCode::Char('q'),
            KeyModifiers::empty(),
        )))
        .unwrap();

    select! {
        biased;

        keep_running = app.draw_requested() => assert!(!keep_running),
        _= yield_now() => panic!("expected the app to quit"),
    }
}