From 956746d3e3b9cd011e4ee4e6c4bef0caca3958b4 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 14 May 2021 10:59:35 +0200 Subject: [PATCH] init --- .gitignore | 1 + Cargo.lock | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 ++++++ README.md | 3 +++ src/main.rs | 21 ++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..be9adab --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,71 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "clipboard_macos" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145a7f9e9b89453bc0a5e32d166456405d389cea5b578f57f1274b1397588a95" +dependencies = [ + "objc", + "objc-foundation", + "objc_id", +] + +[[package]] +name = "clipwatch" +version = "0.1.0" +dependencies = [ + "clipboard_macos", +] + +[[package]] +name = "libc" +version = "0.2.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0850647 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "clipwatch" +version = "0.1.0" +authors = ["JMARyA "] +edition = "2018" + +[dependencies] +clipboard_macos = "0.1.0" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4478fe9 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ClipWatch + +Really simple tool to monitor and print clipboard content to stdout diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a8bf76b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,21 @@ +use clipboard_macos::*; +use std::{thread, time}; + +fn main() { + let c = Clipboard::new().unwrap(); + let mut cstr = String::new(); + let ten_millis = time::Duration::from_millis(10); + + loop { + let nstr = c.read(); + if nstr.is_err() { + continue; + } + let nstr = nstr.unwrap(); + if nstr != cstr { + println!("{}", nstr); + cstr = nstr; + } + thread::sleep(ten_millis); + } +}