Apply clippy suggestions
This commit is contained in:
parent
8514c007d5
commit
f818ae23e1
@ -24,7 +24,6 @@ use ratatui::style::Style;
|
|||||||
// #[derive(Component, Debug)]
|
// #[derive(Component, Debug)]
|
||||||
// pub struct TerminalWindow;
|
// pub struct TerminalWindow;
|
||||||
|
|
||||||
|
|
||||||
/// Marker component for terminal display
|
/// Marker component for terminal display
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
#[component(on_add = on_add_terminal_display)]
|
#[component(on_add = on_add_terminal_display)]
|
||||||
@ -69,8 +68,8 @@ fn on_add_terminal_display(mut world: DeferredWorld, entity: Entity, _id: Compon
|
|||||||
image.resize(size);
|
image.resize(size);
|
||||||
let image_handle = asset_server.add(image);
|
let image_handle = asset_server.add(image);
|
||||||
|
|
||||||
let headless_render_source = HeadlessRenderSource::new(&asset_server, image_handle.clone());
|
let headless_render_source = HeadlessRenderSource::new(asset_server, image_handle.clone());
|
||||||
let post_process_settings = DitherPostProcessSettings::new(dither_level, &asset_server);
|
let post_process_settings = DitherPostProcessSettings::new(dither_level, asset_server);
|
||||||
world
|
world
|
||||||
.commands()
|
.commands()
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
|
@ -20,9 +20,7 @@ impl Default for Terminal {
|
|||||||
stdout().execute(EnterAlternateScreen).unwrap();
|
stdout().execute(EnterAlternateScreen).unwrap();
|
||||||
stdout().execute(EnableMouseCapture).unwrap();
|
stdout().execute(EnableMouseCapture).unwrap();
|
||||||
stdout()
|
stdout()
|
||||||
.execute(PushKeyboardEnhancementFlags(
|
.execute(PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::all()))
|
||||||
KeyboardEnhancementFlags::all(),
|
|
||||||
))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
enable_raw_mode().unwrap();
|
enable_raw_mode().unwrap();
|
||||||
let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout()))
|
let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout()))
|
||||||
|
@ -7,11 +7,7 @@ use bevy::{
|
|||||||
use crossterm::event::{read, Event, KeyEvent, KeyEventKind, MediaKeyCode, ModifierKeyCode};
|
use crossterm::event::{read, Event, KeyEvent, KeyEventKind, MediaKeyCode, ModifierKeyCode};
|
||||||
use smol_str::SmolStr;
|
use smol_str::SmolStr;
|
||||||
|
|
||||||
use super::{
|
use super::{components::DummyWindow, events::TerminalInputEvent, resources::EventQueue};
|
||||||
components::DummyWindow,
|
|
||||||
events::TerminalInputEvent,
|
|
||||||
resources::EventQueue,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Initializes event queue and thread
|
/// Initializes event queue and thread
|
||||||
pub fn setup_input(mut commands: Commands, event_queue: Res<EventQueue>) {
|
pub fn setup_input(mut commands: Commands, event_queue: Res<EventQueue>) {
|
||||||
@ -294,7 +290,7 @@ fn crossterm_keycode_to_bevy_key(
|
|||||||
35 => Some(BKey::F35),
|
35 => Some(BKey::F35),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
CKey::Char(c) => Some(BKey::Character(SmolStr::from(c.encode_utf8(&mut [0;4])))),
|
CKey::Char(c) => Some(BKey::Character(SmolStr::from(c.encode_utf8(&mut [0; 4])))),
|
||||||
CKey::Null => None,
|
CKey::Null => None,
|
||||||
CKey::Esc => Some(BKey::Escape),
|
CKey::Esc => Some(BKey::Escape),
|
||||||
CKey::CapsLock => Some(BKey::CapsLock),
|
CKey::CapsLock => Some(BKey::CapsLock),
|
||||||
|
74
src/lib.rs
74
src/lib.rs
@ -3,21 +3,29 @@
|
|||||||
//! Bevy plugin which allows a camera to render to a terminal window.
|
//! Bevy plugin which allows a camera to render to a terminal window.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::OpenOptions, io::{stdout, Write}, path::PathBuf,
|
fs::OpenOptions,
|
||||||
|
io::{stdout, Write},
|
||||||
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
log::{
|
log::{
|
||||||
tracing_subscriber::{self, layer::SubscriberExt, EnvFilter, Layer, Registry},
|
tracing_subscriber::{self, layer::SubscriberExt, EnvFilter, Layer, Registry},
|
||||||
Level,
|
Level,
|
||||||
}, prelude::*, utils::tracing::subscriber,
|
},
|
||||||
|
prelude::*,
|
||||||
|
utils::tracing::subscriber,
|
||||||
};
|
};
|
||||||
use bevy_dither_post_process::DitherPostProcessPlugin;
|
use bevy_dither_post_process::DitherPostProcessPlugin;
|
||||||
|
|
||||||
use bevy_headless_render::HeadlessRenderPlugin;
|
use bevy_headless_render::HeadlessRenderPlugin;
|
||||||
use color_eyre::config::HookBuilder;
|
use color_eyre::config::HookBuilder;
|
||||||
pub use crossterm;
|
pub use crossterm;
|
||||||
use crossterm::{event::{DisableMouseCapture, PopKeyboardEnhancementFlags}, terminal::{disable_raw_mode, LeaveAlternateScreen}, ExecutableCommand};
|
use crossterm::{
|
||||||
|
event::{DisableMouseCapture, PopKeyboardEnhancementFlags},
|
||||||
|
terminal::{disable_raw_mode, LeaveAlternateScreen},
|
||||||
|
ExecutableCommand,
|
||||||
|
};
|
||||||
pub use ratatui;
|
pub use ratatui;
|
||||||
|
|
||||||
/// Functions and types related to capture and display of world to terminal
|
/// Functions and types related to capture and display of world to terminal
|
||||||
@ -54,7 +62,11 @@ impl Plugin for TerminalDisplayPlugin {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let file_layer = tracing_subscriber::fmt::Layer::new()
|
let file_layer = tracing_subscriber::fmt::Layer::new()
|
||||||
.with_writer(log_file)
|
.with_writer(log_file)
|
||||||
.with_filter(EnvFilter::builder().parse_lossy(format!("{},{}", Level::INFO, "wgpu=error,naga=warn")));
|
.with_filter(EnvFilter::builder().parse_lossy(format!(
|
||||||
|
"{},{}",
|
||||||
|
Level::INFO,
|
||||||
|
"wgpu=error,naga=warn"
|
||||||
|
)));
|
||||||
let subscriber = Registry::default().with(file_layer);
|
let subscriber = Registry::default().with(file_layer);
|
||||||
subscriber::set_global_default(subscriber).unwrap();
|
subscriber::set_global_default(subscriber).unwrap();
|
||||||
|
|
||||||
@ -63,43 +75,45 @@ impl Plugin for TerminalDisplayPlugin {
|
|||||||
let error = error.into_eyre_hook();
|
let error = error.into_eyre_hook();
|
||||||
|
|
||||||
color_eyre::eyre::set_hook(Box::new(move |e| {
|
color_eyre::eyre::set_hook(Box::new(move |e| {
|
||||||
let _ = restore_terminal();
|
restore_terminal();
|
||||||
error(e)
|
error(e)
|
||||||
})).unwrap();
|
}))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::panic::set_hook(Box::new(move |info| {
|
std::panic::set_hook(Box::new(move |info| {
|
||||||
let _ = restore_terminal();
|
restore_terminal();
|
||||||
error!("{info}");
|
error!("{info}");
|
||||||
panic(info);
|
panic(info);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.add_plugins((
|
app.add_plugins((DitherPostProcessPlugin, HeadlessRenderPlugin))
|
||||||
DitherPostProcessPlugin,
|
.add_systems(Startup, input::systems::setup_input)
|
||||||
HeadlessRenderPlugin,
|
.add_systems(
|
||||||
))
|
Update,
|
||||||
.add_systems(Startup, input::systems::setup_input)
|
(
|
||||||
.add_systems(
|
input::systems::input_handling,
|
||||||
Update,
|
display::systems::resize_handling,
|
||||||
(
|
display::systems::print_to_terminal,
|
||||||
input::systems::input_handling,
|
widgets::systems::widget_input_handling,
|
||||||
display::systems::resize_handling,
|
widgets::systems::update_widgets,
|
||||||
display::systems::print_to_terminal,
|
),
|
||||||
widgets::systems::widget_input_handling,
|
)
|
||||||
widgets::systems::update_widgets,
|
.insert_resource(display::resources::Terminal::default())
|
||||||
),
|
.insert_resource(input::resources::EventQueue::default())
|
||||||
)
|
.init_resource::<widgets::resources::FocusedWidget>()
|
||||||
.insert_resource(display::resources::Terminal::default())
|
.add_event::<input::events::TerminalInputEvent>();
|
||||||
.insert_resource(input::resources::EventQueue::default())
|
|
||||||
.init_resource::<widgets::resources::FocusedWidget>()
|
|
||||||
.add_event::<input::events::TerminalInputEvent>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore_terminal() {
|
fn restore_terminal() {
|
||||||
let _ = disable_raw_mode();
|
let _ = disable_raw_mode();
|
||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
let _ = stdout.execute(PopKeyboardEnhancementFlags).unwrap()
|
let _ = stdout
|
||||||
.execute(DisableMouseCapture).unwrap()
|
.execute(PopKeyboardEnhancementFlags)
|
||||||
.execute(LeaveAlternateScreen).unwrap()
|
.unwrap()
|
||||||
|
.execute(DisableMouseCapture)
|
||||||
|
.unwrap()
|
||||||
|
.execute(LeaveAlternateScreen)
|
||||||
|
.unwrap()
|
||||||
.flush();
|
.flush();
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ pub trait TerminalWidgetCommands {
|
|||||||
fn focus_widget(&mut self, widget: Entity);
|
fn focus_widget(&mut self, widget: Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's> TerminalWidgetCommands for Commands<'w,'s> {
|
impl TerminalWidgetCommands for Commands<'_, '_> {
|
||||||
fn focus_widget(&mut self, widget: Entity) {
|
fn focus_widget(&mut self, widget: Entity) {
|
||||||
self.queue(FocusWidgetCommand(widget));
|
self.queue(FocusWidgetCommand(widget));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ pub fn widget_input_handling(
|
|||||||
) {
|
) {
|
||||||
if let Some(entity) = **focused_widget {
|
if let Some(entity) = **focused_widget {
|
||||||
if let Ok(mut widget) = widgets.get_mut(entity) {
|
if let Ok(mut widget) = widgets.get_mut(entity) {
|
||||||
if widget.enabled == true {
|
if widget.enabled {
|
||||||
for event in event_reader.read() {
|
for event in event_reader.read() {
|
||||||
widget.widget.handle_events(event, &mut commands);
|
widget.widget.handle_events(event, &mut commands);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user