mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 22:27:03 +05:30
all: log matcher names and clipboard content when available
This commit is contained in:
parent
e2abe50c03
commit
e7a5ed6982
3 changed files with 94 additions and 0 deletions
14
src/main.rs
14
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],
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue