new features
This commit is contained in:
parent
956746d3e3
commit
6f70194871
4 changed files with 203 additions and 2 deletions
135
Cargo.lock
generated
135
Cargo.lock
generated
|
@ -2,12 +2,65 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block"
|
name = "block"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.67"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "2.33.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
|
"atty",
|
||||||
|
"bitflags",
|
||||||
|
"strsim",
|
||||||
|
"textwrap",
|
||||||
|
"unicode-width",
|
||||||
|
"vec_map",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clipboard_macos"
|
name = "clipboard_macos"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -23,7 +76,28 @@ dependencies = [
|
||||||
name = "clipwatch"
|
name = "clipwatch"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"clap",
|
||||||
"clipboard_macos",
|
"clipboard_macos",
|
||||||
|
"ctrlc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ctrlc"
|
||||||
|
version = "3.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "232295399409a8b7ae41276757b5a1cc21032848d42bff2352261f958b3ca29a"
|
||||||
|
dependencies = [
|
||||||
|
"nix",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.1.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -41,6 +115,18 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc"
|
name = "objc"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
@ -69,3 +155,52 @@ checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"objc",
|
"objc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vec_map"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
|
@ -6,3 +6,5 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clipboard_macos = "0.1.0"
|
clipboard_macos = "0.1.0"
|
||||||
|
clap = "2.0"
|
||||||
|
ctrlc = "3.1.9"
|
39
src/config.rs
Normal file
39
src/config.rs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
use clap::{App, Arg};
|
||||||
|
|
||||||
|
pub fn parse_config() -> Config {
|
||||||
|
let args = App::new("Clipwatch")
|
||||||
|
.version(option_env!("CARGO_PKG_VERSION").unwrap())
|
||||||
|
.author("JMARyA <jmarya0@icloud.com>")
|
||||||
|
.about("Keep an eye on the clipboard")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("ignore-first")
|
||||||
|
.short("i")
|
||||||
|
.long("ignore-first")
|
||||||
|
.help("ignores the value stored in the clipboard at the start of the programm")
|
||||||
|
.takes_value(false),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("summary")
|
||||||
|
.short("s")
|
||||||
|
.long("summary")
|
||||||
|
.help("at termination of the programm a summary will be copied into the clipboard")
|
||||||
|
.takes_value(false),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
return Config::new(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Config {
|
||||||
|
pub ignore_first: bool,
|
||||||
|
pub summary: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
fn new(args: clap::ArgMatches) -> Config {
|
||||||
|
return Config {
|
||||||
|
ignore_first: args.is_present("ignore-first"),
|
||||||
|
summary: args.is_present("summary"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
27
src/main.rs
27
src/main.rs
|
@ -1,10 +1,34 @@
|
||||||
|
mod config;
|
||||||
use clipboard_macos::*;
|
use clipboard_macos::*;
|
||||||
use std::{thread, time};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::{process, thread, time};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let conf = config::parse_config();
|
||||||
|
|
||||||
let c = Clipboard::new().unwrap();
|
let c = Clipboard::new().unwrap();
|
||||||
let mut cstr = String::new();
|
let mut cstr = String::new();
|
||||||
let ten_millis = time::Duration::from_millis(10);
|
let ten_millis = time::Duration::from_millis(10);
|
||||||
|
let stream: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(vec![]));
|
||||||
|
let cp_stream = stream.clone();
|
||||||
|
|
||||||
|
let summary = conf.summary.clone();
|
||||||
|
ctrlc::set_handler(move || {
|
||||||
|
if summary {
|
||||||
|
let mut fstr = String::new();
|
||||||
|
let v = cp_stream.lock().unwrap();
|
||||||
|
for i in 0..v.len() {
|
||||||
|
fstr.push_str(&*format!("{}\n", v[i]));
|
||||||
|
}
|
||||||
|
Clipboard::new().unwrap().write(fstr);
|
||||||
|
}
|
||||||
|
process::exit(0);
|
||||||
|
})
|
||||||
|
.expect("Error setting Ctrl-C handler");
|
||||||
|
|
||||||
|
if conf.ignore_first {
|
||||||
|
cstr = c.read().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let nstr = c.read();
|
let nstr = c.read();
|
||||||
|
@ -13,6 +37,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
let nstr = nstr.unwrap();
|
let nstr = nstr.unwrap();
|
||||||
if nstr != cstr {
|
if nstr != cstr {
|
||||||
|
stream.lock().unwrap().push(nstr.clone());
|
||||||
println!("{}", nstr);
|
println!("{}", nstr);
|
||||||
cstr = nstr;
|
cstr = nstr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue