From 363157a7f831fc29c6ed1a26880ea756521317b9 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Fri, 10 May 2024 20:00:45 -0400 Subject: Truncate Log File --- src/resources.rs | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'src/resources.rs') diff --git a/src/resources.rs b/src/resources.rs index 917f957..a8d5a7f 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -1,8 +1,20 @@ -use std::{sync::{Arc, Mutex}, io::{stdout, Stdout}, fs::{File, OpenOptions}}; - -use bevy::{prelude::*, utils::{HashSet, Uuid, HashMap, tracing::{subscriber, level_filters::LevelFilter}}, log::tracing_subscriber}; -use crossterm::{event::{Event, KeyCode, EnableMouseCapture, PushKeyboardEnhancementFlags, KeyboardEnhancementFlags}, terminal::{EnterAlternateScreen, enable_raw_mode}, ExecutableCommand}; -use ratatui::{backend::CrosstermBackend, Frame, layout::Rect}; +use std::{ + io::{stdout, Stdout}, + sync::{Arc, Mutex}, +}; + +use bevy::{ + prelude::*, + utils::{HashMap, HashSet, Uuid}, +}; +use crossterm::{ + event::{ + EnableMouseCapture, Event, KeyCode, KeyboardEnhancementFlags, PushKeyboardEnhancementFlags, + }, + terminal::{enable_raw_mode, EnterAlternateScreen}, + ExecutableCommand, +}; +use ratatui::{backend::CrosstermBackend, layout::Rect, Frame}; use crate::events::TerminalInputEvent; @@ -47,9 +59,14 @@ impl Default for Terminal { fn default() -> Self { stdout().execute(EnterAlternateScreen).unwrap(); stdout().execute(EnableMouseCapture).unwrap(); - stdout().execute(PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)).unwrap(); + stdout() + .execute(PushKeyboardEnhancementFlags( + KeyboardEnhancementFlags::REPORT_EVENT_TYPES, + )) + .unwrap(); enable_raw_mode().unwrap(); - let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout())).expect("Failed to create terminal"); + let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout())) + .expect("Failed to create terminal"); terminal.clear().expect("Failed to clear terminal"); Self(terminal) } @@ -57,7 +74,7 @@ impl Default for Terminal { #[derive(Resource, Default)] pub struct TerminalUI { - widgets: HashMap> + widgets: HashMap>, } impl TerminalUI { @@ -77,7 +94,7 @@ impl TerminalUI { pub fn widgets(&mut self) -> Vec<&mut Box> { let mut vec = self.widgets.values_mut().collect::>(); - vec.sort_by(|a, b| { a.depth().cmp(&b.depth()).reverse() }); + vec.sort_by(|a, b| a.depth().cmp(&b.depth()).reverse()); vec } } @@ -86,6 +103,8 @@ pub trait TerminalWidget { fn init(&mut self) {} fn update(&mut self) {} fn render(&mut self, frame: &mut Frame, rect: Rect); - fn handle_events(&mut self, _event: &TerminalInputEvent, commands: &mut Commands) {} - fn depth(&self) -> u32 { 0 } + fn handle_events(&mut self, _event: &TerminalInputEvent, _commands: &mut Commands) {} + fn depth(&self) -> u32 { + 0 + } } -- cgit v1.2.3