Truncate Log File
This commit is contained in:
parent
ec8f43e79c
commit
363157a7f8
@ -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"
|
||||
|
@ -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()
|
||||
|
@ -1,8 +1,20 @@
|
||||
use std::{sync::{Arc, Mutex}, io::{stdout, Stdout}, fs::{File, OpenOptions}};
|
||||
use std::{
|
||||
io::{stdout, Stdout},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
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 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<Uuid, Box<dyn TerminalWidget + Sync + Send>>
|
||||
widgets: HashMap<Uuid, Box<dyn TerminalWidget + Sync + Send>>,
|
||||
}
|
||||
|
||||
impl TerminalUI {
|
||||
@ -77,7 +94,7 @@ impl TerminalUI {
|
||||
|
||||
pub fn widgets(&mut self) -> Vec<&mut Box<dyn TerminalWidget + Sync + Send>> {
|
||||
let mut vec = self.widgets.values_mut().collect::<Vec<_>>();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user