Apply clippy suggestions
This commit is contained in:
parent
8514c007d5
commit
f818ae23e1
@ -24,7 +24,6 @@ use ratatui::style::Style;
|
||||
// #[derive(Component, Debug)]
|
||||
// pub struct TerminalWindow;
|
||||
|
||||
|
||||
/// Marker component for terminal display
|
||||
#[derive(Component, Debug)]
|
||||
#[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);
|
||||
let image_handle = asset_server.add(image);
|
||||
|
||||
let headless_render_source = HeadlessRenderSource::new(&asset_server, image_handle.clone());
|
||||
let post_process_settings = DitherPostProcessSettings::new(dither_level, &asset_server);
|
||||
let headless_render_source = HeadlessRenderSource::new(asset_server, image_handle.clone());
|
||||
let post_process_settings = DitherPostProcessSettings::new(dither_level, asset_server);
|
||||
world
|
||||
.commands()
|
||||
.entity(entity)
|
||||
|
@ -20,9 +20,7 @@ impl Default for Terminal {
|
||||
stdout().execute(EnterAlternateScreen).unwrap();
|
||||
stdout().execute(EnableMouseCapture).unwrap();
|
||||
stdout()
|
||||
.execute(PushKeyboardEnhancementFlags(
|
||||
KeyboardEnhancementFlags::all(),
|
||||
))
|
||||
.execute(PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::all()))
|
||||
.unwrap();
|
||||
enable_raw_mode().unwrap();
|
||||
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 smol_str::SmolStr;
|
||||
|
||||
use super::{
|
||||
components::DummyWindow,
|
||||
events::TerminalInputEvent,
|
||||
resources::EventQueue,
|
||||
};
|
||||
use super::{components::DummyWindow, events::TerminalInputEvent, resources::EventQueue};
|
||||
|
||||
/// Initializes event queue and thread
|
||||
pub fn setup_input(mut commands: Commands, event_queue: Res<EventQueue>) {
|
||||
|
42
src/lib.rs
42
src/lib.rs
@ -3,21 +3,29 @@
|
||||
//! Bevy plugin which allows a camera to render to a terminal window.
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions, io::{stdout, Write}, path::PathBuf,
|
||||
fs::OpenOptions,
|
||||
io::{stdout, Write},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use bevy::{
|
||||
log::{
|
||||
tracing_subscriber::{self, layer::SubscriberExt, EnvFilter, Layer, Registry},
|
||||
Level,
|
||||
}, prelude::*, utils::tracing::subscriber,
|
||||
},
|
||||
prelude::*,
|
||||
utils::tracing::subscriber,
|
||||
};
|
||||
use bevy_dither_post_process::DitherPostProcessPlugin;
|
||||
|
||||
use bevy_headless_render::HeadlessRenderPlugin;
|
||||
use color_eyre::config::HookBuilder;
|
||||
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;
|
||||
|
||||
/// Functions and types related to capture and display of world to terminal
|
||||
@ -54,7 +62,11 @@ impl Plugin for TerminalDisplayPlugin {
|
||||
.unwrap();
|
||||
let file_layer = tracing_subscriber::fmt::Layer::new()
|
||||
.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);
|
||||
subscriber::set_global_default(subscriber).unwrap();
|
||||
|
||||
@ -63,20 +75,18 @@ impl Plugin for TerminalDisplayPlugin {
|
||||
let error = error.into_eyre_hook();
|
||||
|
||||
color_eyre::eyre::set_hook(Box::new(move |e| {
|
||||
let _ = restore_terminal();
|
||||
restore_terminal();
|
||||
error(e)
|
||||
})).unwrap();
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
std::panic::set_hook(Box::new(move |info| {
|
||||
let _ = restore_terminal();
|
||||
restore_terminal();
|
||||
error!("{info}");
|
||||
panic(info);
|
||||
}));
|
||||
|
||||
app.add_plugins((
|
||||
DitherPostProcessPlugin,
|
||||
HeadlessRenderPlugin,
|
||||
))
|
||||
app.add_plugins((DitherPostProcessPlugin, HeadlessRenderPlugin))
|
||||
.add_systems(Startup, input::systems::setup_input)
|
||||
.add_systems(
|
||||
Update,
|
||||
@ -98,8 +108,12 @@ impl Plugin for TerminalDisplayPlugin {
|
||||
fn restore_terminal() {
|
||||
let _ = disable_raw_mode();
|
||||
let mut stdout = stdout();
|
||||
let _ = stdout.execute(PopKeyboardEnhancementFlags).unwrap()
|
||||
.execute(DisableMouseCapture).unwrap()
|
||||
.execute(LeaveAlternateScreen).unwrap()
|
||||
let _ = stdout
|
||||
.execute(PopKeyboardEnhancementFlags)
|
||||
.unwrap()
|
||||
.execute(DisableMouseCapture)
|
||||
.unwrap()
|
||||
.execute(LeaveAlternateScreen)
|
||||
.unwrap()
|
||||
.flush();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub trait TerminalWidgetCommands {
|
||||
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) {
|
||||
self.queue(FocusWidgetCommand(widget));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub fn widget_input_handling(
|
||||
) {
|
||||
if let Some(entity) = **focused_widget {
|
||||
if let Ok(mut widget) = widgets.get_mut(entity) {
|
||||
if widget.enabled == true {
|
||||
if widget.enabled {
|
||||
for event in event_reader.read() {
|
||||
widget.widget.handle_events(event, &mut commands);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user