bevy_ratatui/
lib.rs

1//! A collection of plugins for building terminal-based applications with [Bevy] and [Ratatui].
2//!
3//! # Example
4//!
5//! ```rust,no_run
6//! use bevy::{
7//!     app::{AppExit, ScheduleRunnerPlugin},
8//!     prelude::*,
9//! };
10//! use bevy_ratatui::{
11//!     error::exit_on_error, event::KeyEvent, terminal::RatatuiContext, RatatuiPlugins,
12//! };
13//!
14//! fn main() {
15//!     let wait_duration = std::time::Duration::from_secs_f64(1. / 60.); // 60 FPS
16//!     App::new()
17//!         .add_plugins(RatatuiPlugins::default())
18//!         .add_plugins(ScheduleRunnerPlugin::run_loop(wait_duration))
19//!         .add_systems(PreUpdate, keyboard_input_system)
20//!         .add_systems(Update, hello_world.pipe(exit_on_error))
21//!         .run();
22//! }
23//!
24//! fn hello_world(mut context: ResMut<RatatuiContext>) -> color_eyre::Result<()> {
25//!     context.draw(|frame| {
26//!         let text = ratatui::text::Text::raw("hello world\nPress 'q' to Quit");
27//!         frame.render_widget(text, frame.size())
28//!     })?;
29//!     Ok(())
30//! }
31//!
32//! fn keyboard_input_system(mut events: EventReader<KeyEvent>, mut exit: EventWriter<AppExit>) {
33//!     use crossterm::event::KeyCode; // beware bevy prelude also has a KeyCode enum
34//!     for event in events.read() {
35//!         match event.code {
36//!             KeyCode::Char('q') | KeyCode::Esc => {
37//!                 exit.send_default();
38//!             }
39//!             _ => {}
40//!         }
41//!     }
42//! }
43//! ```
44//!
45//! See the [examples] directory for more examples.
46//!
47//! # Input Forwarding
48//!
49//! The terminal input can be forwarded to the bevy input system. See the
50//! [input_forwarding] module documentation for details.
51//!
52//! [Bevy]: https://bevyengine.org
53//! [Ratatui]: https://ratatui.rs
54//! [examples]: https://github.com/cxreiff/bevy_ratatui/tree/main/examples
55
56pub mod error;
57pub mod event;
58pub mod input_forwarding;
59pub mod kitty;
60pub mod mouse;
61mod ratatui;
62pub mod terminal;
63
64pub use ratatui::RatatuiPlugins;