diff options
author | Silas Bartha <[email protected]> | 2024-05-02 02:53:51 -0400 |
---|---|---|
committer | Silas Bartha <[email protected]> | 2024-05-02 02:53:51 -0400 |
commit | 6834194b9e16a7b5ee68b539ceb1a99b8f1ff90b (patch) | |
tree | bac5d0ff699f1c3c4f58d47c2f127f5d3432a528 /src/lib.rs | |
parent | 646db8328611f21a5850cc9834b6c72bfdf0c829 (diff) |
Added ratatui integration + logger redirectv0.1.1
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 68 |
1 files changed, 49 insertions, 19 deletions
@@ -1,13 +1,22 @@ -use std::io::stdout; +use std::{io::stdout, fs::OpenOptions}; -use bevy::prelude::*; +use bevy::{ + log::{ + tracing_subscriber::{self, Registry, prelude::*}, + LogPlugin, Level, + }, + prelude::*, utils::tracing::level_filters::LevelFilter, +}; use crossterm::{ - event::PopKeyboardEnhancementFlags, terminal::disable_raw_mode, ExecutableCommand, + event::DisableMouseCapture, + terminal::{disable_raw_mode, LeaveAlternateScreen}, + ExecutableCommand, }; use grex_dither_post_process::DitherPostProcessPlugin; use grex_framebuffer_extract::FramebufferExtractPlugin; -pub use crossterm::event::KeyCode; +pub use crossterm; +pub use ratatui; pub mod components; pub mod events; @@ -18,26 +27,47 @@ pub struct TerminalDisplayPlugin; impl Plugin for TerminalDisplayPlugin { fn build(&self, app: &mut App) { - app.add_plugins((DitherPostProcessPlugin, FramebufferExtractPlugin)) - .add_systems(Startup, systems::setup) - .add_systems( - Update, - ( - systems::input_handling, - systems::resize_handling, - systems::print_to_terminal, - ), - ) - .insert_resource(resources::EventQueue::default()) - .insert_resource(resources::TerminalInput::default()) - .add_event::<events::TerminalInputEvent>(); + app.add_plugins(( + DitherPostProcessPlugin, + FramebufferExtractPlugin, + LogPlugin { + update_subscriber: Some(|_| { + let log_file = OpenOptions::new() + .write(true) + .create(true) + .open("debug.log") + .unwrap(); + let file_layer = tracing_subscriber::fmt::Layer::new() + .with_writer(log_file) + .with_filter(LevelFilter::from_level(Level::INFO)); + Box::new(Registry::default().with(file_layer)) + }), + ..Default::default() + }, + )) + .add_systems(Startup, systems::setup) + .add_systems( + Update, + ( + systems::input_handling, + systems::resize_handling, + systems::print_to_terminal, + systems::widget_input_handling, + ), + ) + .insert_resource(resources::Terminal::default()) + .insert_resource(resources::EventQueue::default()) + .insert_resource(resources::TerminalInput::default()) + .insert_resource(resources::TerminalUI::default()) + .add_event::<events::TerminalInputEvent>(); } } impl Drop for TerminalDisplayPlugin { fn drop(&mut self) { let mut stdout = stdout(); - stdout.execute(PopKeyboardEnhancementFlags).unwrap(); - disable_raw_mode().unwrap(); + let _ = stdout.execute(DisableMouseCapture); + let _ = stdout.execute(LeaveAlternateScreen); + let _ = disable_raw_mode(); } } |