Expand description
A collection of plugins for building terminal-based applications with Bevy and Ratatui.
§Example
use std::time::Duration;
use bevy::{
app::{AppExit, ScheduleRunnerPlugin},
prelude::*,
};
use bevy_ratatui::{event::KeyMessage, RatatuiContext, RatatuiPlugins};
use ratatui::crossterm::event::KeyCode;
use ratatui::text::Text;
fn main() {
let frame_time = Duration::from_secs_f32(1. / 60.);
App::new()
.add_plugins((
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(frame_time)),
RatatuiPlugins::default(),
))
.add_systems(PreUpdate, input_system)
.add_systems(Update, draw_system)
.run();
}
fn draw_system(mut context: ResMut<RatatuiContext>) -> Result {
context.draw(|frame| {
let text = Text::raw("hello world\npress 'q' to quit");
frame.render_widget(text, frame.area());
})?;
Ok(())
}
fn input_system(mut messages: MessageReader<KeyMessage>, mut exit: MessageWriter<AppExit>) {
for message in messages.read() {
if let KeyCode::Char('q') = message.code {
exit.write_default();
}
}
}See the examples directory for more examples.
§Input Forwarding
The terminal input can be forwarded to the bevy input system. See the [input_forwarding] module documentation for details.
Re-exports§
pub use ratatui::crossterm;
Modules§
Structs§
- Ratatui
Context - A bevy Resource that wraps ratatui::Terminal, setting up the terminal context when initialized (i.e. entering raw mode), restores the prior terminal state when dropped (i.e. exiting raw mode), and can be brought into Bevy systems to interact with Ratatui. For example, use this resource to draw to the terminal each frame, like the below example.
- Ratatui
Plugins - A plugin group that includes all the plugins in the Ratatui crate.