Expand description
A collection of plugins for building terminal-based applications with Bevy and Ratatui.
§Example
use bevy::{
app::{AppExit, ScheduleRunnerPlugin},
prelude::*,
};
use bevy_ratatui::{
error::exit_on_error, event::KeyEvent, terminal::RatatuiContext, RatatuiPlugins,
};
fn main() {
let wait_duration = std::time::Duration::from_secs_f64(1. / 60.); // 60 FPS
App::new()
.add_plugins(RatatuiPlugins::default())
.add_plugins(ScheduleRunnerPlugin::run_loop(wait_duration))
.add_systems(PreUpdate, keyboard_input_system)
.add_systems(Update, hello_world.pipe(exit_on_error))
.run();
}
fn hello_world(mut context: ResMut<RatatuiContext>) -> color_eyre::Result<()> {
context.draw(|frame| {
let text = ratatui::text::Text::raw("hello world\nPress 'q' to Quit");
frame.render_widget(text, frame.size())
})?;
Ok(())
}
fn keyboard_input_system(mut events: EventReader<KeyEvent>, mut exit: EventWriter<AppExit>) {
use crossterm::event::KeyCode; // beware bevy prelude also has a KeyCode enum
for event in events.read() {
match event.code {
KeyCode::Char('q') | KeyCode::Esc => {
exit.send_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.
Modules§
- Error handling for the app.
- Event handling.
- Forwards terminal key events to the bevy input system.
- Enhanced kitty keyboard protocol.
- Mouse support.
- This module contains the terminal plugin and the RatatuiContext resource.
Structs§
- A plugin group that includes all the plugins in the Ratatui crate.