A (forked) rust crate for using Ratatui in a Bevy application.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

miscellaneous fixes for examples

authored by

zombkit and committed by
Cooper Reiff
ee2919ec 9c0b9d77

+49 -35
+2 -2
Cargo.lock
··· 4164 4164 4165 4165 [[package]] 4166 4166 name = "soft_ratatui" 4167 - version = "0.0.7" 4167 + version = "0.0.8" 4168 4168 source = "registry+https://github.com/rust-lang/crates.io-index" 4169 - checksum = "cc09d84d7266319a84255142563d5c295d887cff6a3d97eac8b359e421c30dc7" 4169 + checksum = "b6f86103b6d0ae58ba8be0939008b32d919ba6f504e7c46a14254dbe33452de8" 4170 4170 dependencies = [ 4171 4171 "cosmic-text 0.14.2", 4172 4172 "ratatui",
+1 -1
Cargo.toml
··· 17 17 crossterm = "0.29.0" 18 18 ratatui = { version = "0.29.0", features = ["unstable-widget-ref"] } 19 19 smol_str = "0.2.2" 20 - soft_ratatui = { version = "0.0.7", optional = true } 20 + soft_ratatui = { version = "0.0.8", optional = true } 21 21 tracing = "0.1.41" 22 22 23 23 [dev-dependencies]
+2 -5
examples/bevy_keys.rs
··· 6 6 prelude::*, 7 7 }; 8 8 use bevy_ratatui::{ 9 - RatatuiPlugins, 10 - event::KeyEvent, 11 - input_forwarding::{Capability, Detected, Emulate, EmulationPolicy, ReleaseKey}, 12 - kitty::KittyEnabled, 13 - terminal::RatatuiContext, 9 + Capability, Detected, Emulate, EmulationPolicy, KeyEvent, KittyEnabled, RatatuiContext, 10 + RatatuiPlugins, ReleaseKey, 14 11 }; 15 12 use crossterm::event::KeyEventKind; 16 13 use ratatui::text::Text;
+1 -1
examples/demo.rs
··· 44 44 45 45 #[cfg(feature = "windowed")] 46 46 app.add_plugins(( 47 - DefaultPlugins, 47 + DefaultPlugins.set(ImagePlugin::default_nearest()), 48 48 RatatuiPlugins { 49 49 enable_input_forwarding: true, 50 50 ..default()
+26 -14
examples/hello_world.rs
··· 1 - use std::time::Duration; 2 - 3 - use bevy::{ 4 - app::{AppExit, ScheduleRunnerPlugin}, 5 - prelude::*, 6 - }; 7 - use bevy_ratatui::{ 8 - RatatuiPlugins, 9 - context::{KeyEvent, RatatuiContext}, 10 - }; 1 + use bevy::{app::AppExit, prelude::*}; 2 + #[cfg(not(feature = "windowed"))] 3 + use bevy_ratatui::KeyEvent; 4 + use bevy_ratatui::{RatatuiContext, RatatuiPlugins}; 5 + #[cfg(not(feature = "windowed"))] 11 6 use crossterm::event::KeyCode; 12 7 use ratatui::text::Text; 13 8 14 9 fn main() { 15 - let frame_time = Duration::from_secs_f32(1. / 60.); 16 - 10 + #[cfg(not(feature = "windowed"))] 17 11 App::new() 18 12 .add_plugins(( 19 - MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(frame_time)), 13 + MinimalPlugins.set(bevy::app::ScheduleRunnerPlugin::run_loop( 14 + std::time::Duration::from_secs_f32(1. / 60.), 15 + )), 20 16 RatatuiPlugins::default(), 21 17 )) 22 18 .add_systems(PreUpdate, input_system) 23 19 .add_systems(Update, draw_system) 24 20 .run(); 21 + #[cfg(feature = "windowed")] 22 + App::new() 23 + .add_plugins(( 24 + DefaultPlugins.set(ImagePlugin::default_nearest()), 25 + RatatuiPlugins::default(), 26 + )) 27 + .add_systems(PreUpdate, input_system_windowed) 28 + .add_systems(Update, draw_system) 29 + .run(); 25 30 } 26 31 27 32 fn draw_system(mut context: ResMut<RatatuiContext>) -> Result { ··· 32 37 33 38 Ok(()) 34 39 } 35 - 40 + #[cfg(not(feature = "windowed"))] 36 41 fn input_system(mut events: EventReader<KeyEvent>, mut exit: EventWriter<AppExit>) { 37 42 for event in events.read() { 38 43 if let KeyCode::Char('q') = event.code { ··· 40 45 } 41 46 } 42 47 } 48 + 49 + #[cfg(feature = "windowed")] 50 + fn input_system_windowed(keys: Res<ButtonInput<KeyCode>>, mut app_exit: EventWriter<AppExit>) { 51 + if keys.just_pressed(KeyCode::KeyQ) { 52 + app_exit.write_default(); 53 + } 54 + }
+1 -3
examples/kitty.rs
··· 2 2 app::{AppExit, ScheduleRunnerPlugin}, 3 3 prelude::*, 4 4 }; 5 - use bevy_ratatui::{ 6 - RatatuiPlugins, event::KeyEvent, kitty::KittyEnabled, terminal::RatatuiContext, 7 - }; 5 + use bevy_ratatui::{KeyEvent, KittyEnabled, RatatuiContext, RatatuiPlugins}; 8 6 use crossterm::event::KeyEventKind; 9 7 use ratatui::text::Text; 10 8
+1 -5
examples/mouse.rs
··· 2 2 app::{AppExit, ScheduleRunnerPlugin}, 3 3 prelude::*, 4 4 }; 5 - use bevy_ratatui::{ 6 - RatatuiPlugins, 7 - event::{KeyEvent, MouseEvent}, 8 - terminal::RatatuiContext, 9 - }; 5 + use bevy_ratatui::{KeyEvent, MouseEvent, RatatuiContext, RatatuiPlugins}; 10 6 use crossterm::event::MouseEventKind; 11 7 use rand::prelude::*; 12 8
+1 -1
src/crossterm_context/mod.rs
··· 2 2 pub mod context; 3 3 mod error; 4 4 pub mod events; 5 - mod kitty; 5 + pub mod kitty; 6 6 mod mouse; 7 7 pub mod translation;
+2
src/lib.rs
··· 65 65 pub use context_trait::TerminalContext; 66 66 pub use crossterm_context::context::CrosstermContext; 67 67 pub use crossterm_context::events::KeyEvent; 68 + pub use crossterm_context::events::MouseEvent; 69 + pub use crossterm_context::kitty::KittyEnabled; 68 70 pub use crossterm_context::translation::*; 69 71 pub use plugins::RatatuiPlugins; 70 72 pub use ratatui_context::RatatuiContext;
+12 -3
src/windowed_context/other.rs
··· 40 40 }, 41 41 TextureDimension::D2, 42 42 data, 43 - TextureFormat::Rgba8Unorm, 43 + TextureFormat::Rgba8UnormSrgb, 44 44 RenderAssetUsages::RENDER_WORLD | RenderAssetUsages::MAIN_WORLD, 45 45 ); 46 46 let handle = images.add(image); 47 - commands.spawn(Sprite::from_image(handle.clone())); 47 + commands.spawn(( 48 + ImageNode::new(handle.clone()), 49 + Node { 50 + justify_self: JustifySelf::Center, 51 + align_self: AlignSelf::Center, 52 + ..default() 53 + }, 54 + )); 55 + 48 56 commands.insert_resource(TerminalRender(handle)); 57 + 49 58 Ok(()) 50 59 } 51 60 ··· 67 76 }, 68 77 TextureDimension::D2, 69 78 data, 70 - TextureFormat::Rgba8Unorm, 79 + TextureFormat::Rgba8UnormSrgb, 71 80 RenderAssetUsages::RENDER_WORLD | RenderAssetUsages::MAIN_WORLD, 72 81 ); 73 82 }