From b7016f117077ed92ed5a196efc989add203c2b3b Mon Sep 17 00:00:00 2001 From: Daniel Berg Date: Sat, 14 Dec 2024 12:47:42 +0100 Subject: [PATCH] feat: add verbose logging with flag --- src/lib.rs | 13 +++++++++++++ src/main.rs | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 81083bd..b487a9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,9 @@ use config::Config; use std::error::Error; use std::fmt; use std::io; +use std::sync::atomic::{AtomicBool, Ordering}; + +pub static VERBOSE: AtomicBool = AtomicBool::new(false); #[derive(Debug)] pub enum AppError { @@ -262,6 +265,9 @@ pub fn update_tree( // Only send command if name changed if old != &new { let command = format!("rename workspace \"{}\" to \"{}\"", old, new); + if VERBOSE.load(Ordering::Relaxed) { + println!("[COMMAND] {}", command); + } conn.run_command(command)?; } } @@ -275,6 +281,9 @@ pub fn handle_window_event( config: &Config, res: ®ex::Compiled, ) -> Result<(), AppError> { + if VERBOSE.load(Ordering::Relaxed) { + println!("[WINDOW EVENT] Change: {:?}, Container: {:?}", e.change, e.container); + } match e.change { WindowChange::New | WindowChange::Close | WindowChange::Move | WindowChange::Title => { update_tree(conn, config, res) @@ -292,6 +301,10 @@ pub fn handle_ws_event( config: &Config, res: ®ex::Compiled, ) -> Result<(), AppError> { + if VERBOSE.load(Ordering::Relaxed) { + println!("[WORKSPACE EVENT] Change: {:?}, Current: {:?}, Old: {:?}", + e.change, e.current, e.old); + } match e.change { WorkspaceChange::Empty | WorkspaceChange::Focus => { update_tree(conn, config, res) diff --git a/src/main.rs b/src/main.rs index 9f31f6b..55034b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,9 @@ impl Properties { #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { + /// Enable verbose logging + #[arg(short, long)] + verbose: bool, /// Path to toml config file #[arg(short, long)] config: Option, @@ -111,6 +114,9 @@ fn apply_args_to_config(config: &mut Config, args: &Args) { fn setup() -> Result { let args = Args::parse(); + // Set verbose mode if requested + i3wsr::VERBOSE.store(args.verbose, std::sync::atomic::Ordering::Relaxed); + let mut config = load_config(args.config.as_deref())?; apply_args_to_config(&mut config, &args);