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 --- Cargo.toml | 3 +-- src/lib.rs | 1 + src/resources.rs | 41 ++++++++++++++++++++++++++++++----------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ac7802..127e808 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grex_terminal_display" -version = "0.1.2" +version = "0.1.3" edition = "2021" [dependencies] @@ -8,7 +8,6 @@ crossterm = "0.27.0" [dependencies.bevy] version = "0.13" -features = ["dynamic_linking"] [dependencies.grex_framebuffer_extract] git = "https://github.com/exvacuum/grex_framebuffer_extract" diff --git a/src/lib.rs b/src/lib.rs index 3d5b144..92e1809 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ impl Plugin for TerminalDisplayPlugin { let log_file = OpenOptions::new() .write(true) .create(true) + .truncate(true) .open("debug.log") .unwrap(); let file_layer = tracing_subscriber::fmt::Layer::new() 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