diff --git a/src/bridge/linux.rs b/src/bridge/linux.rs index d7ceede..74562ea 100644 --- a/src/bridge/linux.rs +++ b/src/bridge/linux.rs @@ -33,7 +33,12 @@ extern "C" { pub fn get_active_window_executable(buffer: *mut c_char, size: i32) -> i32; pub fn is_current_window_special() -> i32; pub fn register_error_callback( - cb: extern "C" fn(_self: *mut c_void, error_code: c_char, request_code: c_char, minor_code: c_char), + cb: extern "C" fn( + _self: *mut c_void, + error_code: c_char, + request_code: c_char, + minor_code: c_char, + ), ); // Keyboard diff --git a/src/cli.rs b/src/cli.rs index 645d64d..f2fc91b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -17,9 +17,9 @@ * along with espanso. If not, see . */ -use serde::Serialize; use crate::config::ConfigSet; use crate::matcher::{Match, MatchContentType}; +use serde::Serialize; pub fn list_matches(config_set: ConfigSet, onlytriggers: bool, preserve_newlines: bool) { let matches = filter_matches(config_set); @@ -28,19 +28,19 @@ pub fn list_matches(config_set: ConfigSet, onlytriggers: bool, preserve_newlines for trigger in m.triggers.iter() { if onlytriggers { println!("{}", trigger); - }else { + } else { match m.content { MatchContentType::Text(ref text) => { let replace = if preserve_newlines { text.replace.to_owned() - }else{ + } else { text.replace.replace("\n", " ") }; println!("{} - {}", trigger, replace) - }, + } MatchContentType::Image(_) => { // Skip image matches for now - }, + } } } } @@ -60,15 +60,13 @@ pub fn list_matches_as_json(config_set: ConfigSet) { for m in matches { match m.content { - MatchContentType::Text(ref text) => { - entries.push(JsonMatchEntry { - triggers: m.triggers, - replace: text.replace.clone(), - }) - }, + MatchContentType::Text(ref text) => entries.push(JsonMatchEntry { + triggers: m.triggers, + replace: text.replace.clone(), + }), MatchContentType::Image(_) => { // Skip image matches for now - }, + } } } @@ -82,8 +80,8 @@ fn filter_matches(config_set: ConfigSet) -> Vec { output.extend(config_set.default.matches); // TODO: consider specific matches by class, title or exe path -// for specific in config_set.specific { -// output.extend(specific.matches) -// } + // for specific in config_set.specific { + // output.extend(specific.matches) + // } output -} \ No newline at end of file +} diff --git a/src/config/mod.rs b/src/config/mod.rs index 645e7c7..3e68ea1 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -129,7 +129,7 @@ fn default_show_notifications() -> bool { true } fn default_auto_restart() -> bool { - true + true } fn default_show_icon() -> bool { true diff --git a/src/context/linux.rs b/src/context/linux.rs index c1acae9..2d0fe54 100644 --- a/src/context/linux.rs +++ b/src/context/linux.rs @@ -163,5 +163,8 @@ extern "C" fn error_callback( request_code: c_char, minor_code: c_char, ) { - warn!("X11 reported an error code: {}, request_code: {} and minor_code: {}", error_code, request_code, minor_code); + warn!( + "X11 reported an error code: {}, request_code: {} and minor_code: {}", + error_code, request_code, minor_code + ); } diff --git a/src/engine.rs b/src/engine.rs index 2a4d060..f48c810 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -136,16 +136,24 @@ impl< fn find_match_by_trigger(&self, trigger: &str) -> Option { let config = self.config_manager.active_config(); - if let Some(m) = config.matches.iter().find(|m| - m.triggers.iter().any(|t| t == trigger) - ) { + if let Some(m) = config + .matches + .iter() + .find(|m| m.triggers.iter().any(|t| t == trigger)) + { Some(m.clone()) - }else{ + } else { None } } - fn inject_match(&self, m: &Match, trailing_separator: Option, trigger_offset: usize, skip_delete: bool) { + fn inject_match( + &self, + m: &Match, + trailing_separator: Option, + trigger_offset: usize, + skip_delete: bool, + ) { let config = self.config_manager.active_config(); if !config.enable_active { @@ -455,10 +463,8 @@ impl< match m { Some(m) => { self.inject_match(&m, None, 0, true); - }, - None => { - warn!("No match found with trigger: {}", trigger) - }, + } + None => warn!("No match found with trigger: {}", trigger), } } } diff --git a/src/extension/script.rs b/src/extension/script.rs index 8d68c46..6144854 100644 --- a/src/extension/script.rs +++ b/src/extension/script.rs @@ -88,7 +88,8 @@ impl super::Extension for ScriptExtension { match output { Ok(output) => { - let mut output_str = String::from_utf8_lossy(output.stdout.as_slice()).to_string(); + let mut output_str = + String::from_utf8_lossy(output.stdout.as_slice()).to_string(); let error_str = String::from_utf8_lossy(output.stderr.as_slice()); let error_str = error_str.to_string(); let error_str = error_str.trim(); @@ -103,7 +104,7 @@ impl super::Extension for ScriptExtension { let should_trim = if let Some(value) = trim_opt { let val = value.as_bool(); val.unwrap_or(true) - }else{ + } else { true }; @@ -154,10 +155,7 @@ mod tests { Value::from("args"), Value::from(vec!["echo", "hello world"]), ); - params.insert( - Value::from("trim"), - Value::from(false), - ); + params.insert(Value::from("trim"), Value::from(false)); let extension = ScriptExtension::new(); let output = extension.calculate(¶ms, &vec![]); diff --git a/src/extension/shell.rs b/src/extension/shell.rs index 09ec1ad..f1b9da4 100644 --- a/src/extension/shell.rs +++ b/src/extension/shell.rs @@ -46,32 +46,32 @@ impl Shell { let mut command = Command::new("cmd"); command.args(&["/C", &cmd]); command - }, + } Shell::Powershell => { let mut command = Command::new("powershell"); command.args(&["-Command", &cmd]); command - }, + } Shell::WSL => { let mut command = Command::new("bash"); command.args(&["-c", &cmd]); command - }, + } Shell::WSL2 => { let mut command = Command::new("wsl"); command.args(&["bash", "-c", &cmd]); command - }, + } Shell::Bash => { let mut command = Command::new("bash"); command.args(&["-c", &cmd]); command - }, + } Shell::Sh => { let mut command = Command::new("sh"); command.args(&["-c", &cmd]); command - }, + } }; // Inject the $CONFIG variable @@ -176,7 +176,7 @@ impl super::Extension for ShellExtension { let should_trim = if let Some(value) = trim_opt { let val = value.as_bool(); val.unwrap_or(true) - }else{ + } else { true }; diff --git a/src/main.rs b/src/main.rs index 3becc92..12f602d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,6 +53,7 @@ use crate::ui::UIManager; mod bridge; mod check; +mod cli; mod clipboard; mod config; mod context; @@ -69,7 +70,6 @@ mod render; mod sysdaemon; mod system; mod ui; -mod cli; mod utils; const VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -519,18 +519,14 @@ fn register_signals(_: Configs) {} fn register_signals(config: Configs) { // On Unix, also listen for signals so that we can terminate the // worker if the daemon receives a signal - use signal_hook::{iterator::Signals, SIGTERM, SIGINT}; + use signal_hook::{iterator::Signals, SIGINT, SIGTERM}; let signals = Signals::new(&[SIGTERM, SIGINT]).expect("unable to register for signals"); thread::Builder::new() .name("signal monitor".to_string()) .spawn(move || { for signal in signals.forever() { info!("Received signal: {:?}, terminating worker", signal); - send_command_or_warn( - Service::Worker, - config, - IPCCommand::exit_worker(), - ); + send_command_or_warn(Service::Worker, config, IPCCommand::exit_worker()); std::thread::sleep(Duration::from_millis(200)); @@ -1268,7 +1264,6 @@ fn path_main(_config_set: ConfigSet, matches: &ArgMatches) { } } - fn match_main(config_set: ConfigSet, matches: &ArgMatches) { if let Some(matches) = matches.subcommand_matches("list") { let json = matches.is_present("json"); @@ -1277,10 +1272,10 @@ fn match_main(config_set: ConfigSet, matches: &ArgMatches) { if !json { crate::cli::list_matches(config_set, onlytriggers, preserve_newlines); - }else{ + } else { crate::cli::list_matches_as_json(config_set); } - }else if let Some(matches) = matches.subcommand_matches("exec") { + } else if let Some(matches) = matches.subcommand_matches("exec") { let trigger = matches.value_of("trigger").unwrap_or_else(|| { eprintln!("missing trigger"); exit(1); diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 563e560..a609160 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -67,9 +67,7 @@ impl IPCCommand { "notify" => Some(Event::System(SystemEvent::NotifyRequest( self.payload.clone(), ))), - "trigger" => Some(Event::System(SystemEvent::Trigger( - self.payload.clone(), - ))), + "trigger" => Some(Event::System(SystemEvent::Trigger(self.payload.clone()))), _ => None, } } diff --git a/src/protocol/windows.rs b/src/protocol/windows.rs index 9cf239c..10ff042 100644 --- a/src/protocol/windows.rs +++ b/src/protocol/windows.rs @@ -23,10 +23,10 @@ use std::net::{TcpListener, TcpStream}; use std::sync::mpsc::Sender; use crate::config::Configs; +use crate::context; use crate::event::*; use crate::protocol::{process_event, send_command, Service}; -use named_pipe::{PipeOptions, PipeServer, PipeClient}; -use crate::context; +use named_pipe::{PipeClient, PipeOptions, PipeServer}; use std::io::Error; use std::path::PathBuf; @@ -46,12 +46,8 @@ fn get_pipe_name(service: &Service) -> String { } } - impl WindowsIPCServer { - pub fn new( - service: Service, - event_channel: Sender, - ) -> WindowsIPCServer { + pub fn new(service: Service, event_channel: Sender) -> WindowsIPCServer { WindowsIPCServer { service, event_channel, @@ -68,13 +64,12 @@ impl super::IPCServer for WindowsIPCServer { .spawn(move || { let options = PipeOptions::new(&pipe_name); - info!( - "Binding to named pipe: {}", - pipe_name - ); + info!("Binding to named pipe: {}", pipe_name); loop { - let server = options.single().expect("unable to initialize IPC named pipe"); + let server = options + .single() + .expect("unable to initialize IPC named pipe"); let pipe_server = server.wait(); process_event(&event_channel, pipe_server); } diff --git a/src/system/macos.rs b/src/system/macos.rs index 584c26e..f6f6ec0 100644 --- a/src/system/macos.rs +++ b/src/system/macos.rs @@ -106,11 +106,12 @@ impl MacSystemManager { if let Ok(path) = string { if !path.trim().is_empty() { let process = path.trim().to_string(); - let app_name = if let Some(name) = Self::get_app_name_from_path(&process) { - name - } else { - process.to_owned() - }; + let app_name = + if let Some(name) = Self::get_app_name_from_path(&process) { + name + } else { + process.to_owned() + }; return Some((app_name, process)); } @@ -138,14 +139,15 @@ impl MacSystemManager { } } - #[cfg(test)] mod tests { use super::*; #[test] fn test_get_app_name_from_path() { - let app_name = MacSystemManager::get_app_name_from_path("/Applications/iTerm.app/Contents/MacOS/iTerm2"); + let app_name = MacSystemManager::get_app_name_from_path( + "/Applications/iTerm.app/Contents/MacOS/iTerm2", + ); assert_eq!(app_name.unwrap(), "iTerm") } @@ -161,4 +163,3 @@ mod tests { assert_eq!(app_name.unwrap(), "SecurityAgent") } } -