diff --git a/Cargo.lock b/Cargo.lock index d350e49..56e1aa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -55,6 +66,8 @@ dependencies = [ "anyhow", "clipboard", "dirs", + "log", + "pretty_env_logger", "regex", "serde", "serde_derive", @@ -90,6 +103,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "getrandom" version = "0.2.3" @@ -101,6 +127,24 @@ dependencies = [ "wasi", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "libc" version = "0.2.107" @@ -160,6 +204,16 @@ dependencies = [ "objc", ] +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger", + "log", +] + [[package]] name = "proc-macro2" version = "1.0.32" @@ -169,6 +223,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.10" @@ -242,6 +302,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "toml" version = "0.5.8" @@ -279,6 +348,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index ceb83e0..94bc2d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,8 @@ readme = "README.md" anyhow = "1.0.45" clipboard = "0.5.0" dirs = "4.0.0" +log = "0.4.14" +pretty_env_logger = "0.4.0" regex = "1.5.4" serde = "1.0.130" serde_derive = "1.0.130" diff --git a/src/main.rs b/src/main.rs index f45f71f..ae80271 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,16 @@ mod config; +use std::ops::Not; + use anyhow::{anyhow, Result}; use clipboard::{ClipboardContext, ClipboardProvider}; use dirs::config_dir; +use log::debug; use crate::config::{Act, Match, Replacements}; fn main() -> Result<()> { + pretty_env_logger::init(); let mut config_path = config_dir().ok_or(anyhow!("Failed to get config dir"))?; config_path.push("substitutor"); config_path.push("config"); @@ -26,8 +30,18 @@ fn main() -> Result<()> { .iter() .find(|subst| subst.matcher.clone().check_match(&contents)) { + if subst.name.is_empty().not() { + debug!("{}: matched on {}...", &subst.name, truncate(&contents, 40)); + } let result = subst.action.clone().apply_action(contents); let _ = clipboard.set_contents(result); }; } } + +fn truncate(s: &str, max_chars: usize) -> &str { + match s.char_indices().nth(max_chars) { + None => s, + Some((idx, _)) => &s[..idx], + } +}