Fix formatting

This commit is contained in:
Federico Terzi 2020-06-24 22:11:01 +02:00
parent 958d0669e9
commit 45bcaee54b
11 changed files with 73 additions and 74 deletions

View File

@ -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

View File

@ -17,9 +17,9 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
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<Match> {
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
}
}

View File

@ -129,7 +129,7 @@ fn default_show_notifications() -> bool {
true
}
fn default_auto_restart() -> bool {
true
true
}
fn default_show_icon() -> bool {
true

View File

@ -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
);
}

View File

@ -136,16 +136,24 @@ impl<
fn find_match_by_trigger(&self, trigger: &str) -> Option<Match> {
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<char>, trigger_offset: usize, skip_delete: bool) {
fn inject_match(
&self,
m: &Match,
trailing_separator: Option<char>,
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),
}
}
}

View File

@ -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(&params, &vec![]);

View File

@ -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
};

View File

@ -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);

View File

@ -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,
}
}

View File

@ -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<Event>,
) -> WindowsIPCServer {
pub fn new(service: Service, event_channel: Sender<Event>) -> 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);
}

View File

@ -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")
}
}