Skip to content

Commit

Permalink
feat: add verbose logging with flag
Browse files Browse the repository at this point in the history
  • Loading branch information
roosta committed Dec 14, 2024
1 parent 3f43798 commit b7016f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)?;
}
}
Expand All @@ -275,6 +281,9 @@ pub fn handle_window_event(
config: &Config,
res: &regex::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)
Expand All @@ -292,6 +301,10 @@ pub fn handle_ws_event(
config: &Config,
res: &regex::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)
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -111,6 +114,9 @@ fn apply_args_to_config(config: &mut Config, args: &Args) {
fn setup() -> Result<Config, AppError> {
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);

Expand Down

0 comments on commit b7016f1

Please sign in to comment.