From b248cc570ecdd3962e597b2671bcad2590209067 Mon Sep 17 00:00:00 2001 From: nimaaskarian Date: Fri, 2 Feb 2024 12:25:07 +0330 Subject: [PATCH] Removed unnecessary dependencies Removed clipboard feature --- Cargo.lock | 410 ------------------------------------------ Cargo.toml | 2 - src/fileio.rs | 7 +- src/todo_list/todo.rs | 16 +- src/tui/app.rs | 42 ++--- 5 files changed, 34 insertions(+), 443 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 889e657..a59e96f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "ahash" version = "0.8.7" @@ -89,25 +83,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "arboard" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafb29b107435aa276664c1db8954ac27a6e105cdad3c88287a199eb0e313c08" -dependencies = [ - "clipboard-win", - "core-graphics", - "image", - "log", - "objc", - "objc-foundation", - "objc_id", - "parking_lot", - "thiserror", - "winapi", - "x11rb", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -126,12 +101,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" -[[package]] -name = "block" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" - [[package]] name = "block-buffer" version = "0.10.4" @@ -147,28 +116,14 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" -[[package]] -name = "bytemuck" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "c3" version = "0.3.6" dependencies = [ - "arboard", "chrono", "clap", "crossterm", "home", - "rand", "ratatui", "scanf", "sha1", @@ -250,69 +205,18 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" -[[package]] -name = "clipboard-win" -version = "4.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" -dependencies = [ - "error-code", - "str-buf", - "winapi", -] - -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - [[package]] name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" -[[package]] -name = "core-graphics" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", - "foreign-types", - "libc", -] - -[[package]] -name = "core-graphics-types" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "libc", -] - [[package]] name = "cpufeatures" version = "0.2.11" @@ -322,15 +226,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - [[package]] name = "crossterm" version = "0.27.0" @@ -382,50 +277,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "error-code" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" -dependencies = [ - "libc", - "str-buf", -] - -[[package]] -name = "fdeflate" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "209098dd6dfc4445aa6111f0e98653ac323eaa4dfd212c9ca3931bf9955c31bd" -dependencies = [ - "simd-adler32", -] - -[[package]] -name = "flate2" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "generic-array" version = "0.14.7" @@ -436,27 +287,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "gethostname" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "getrandom" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "hashbrown" version = "0.14.3" @@ -505,21 +335,6 @@ dependencies = [ "cc", ] -[[package]] -name = "image" -version = "0.24.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "num-rational", - "num-traits", - "png", - "tiff", -] - [[package]] name = "indoc" version = "2.0.4" @@ -535,12 +350,6 @@ dependencies = [ "either", ] -[[package]] -name = "jpeg-decoder" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" - [[package]] name = "js-sys" version = "0.3.67" @@ -581,46 +390,18 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - [[package]] name = "memchr" version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", - "simd-adler32", -] - [[package]] name = "mio" version = "0.8.10" @@ -633,18 +414,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "nix" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nom" version = "7.1.3" @@ -655,27 +424,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.17" @@ -685,35 +433,6 @@ dependencies = [ "autocfg", ] -[[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", -] - [[package]] name = "once_cell" version = "1.19.0" @@ -749,25 +468,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "png" -version = "0.17.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" -dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro2" version = "1.0.71" @@ -786,36 +486,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "ratatui" version = "0.25.0" @@ -906,12 +576,6 @@ dependencies = [ "libc", ] -[[package]] -name = "simd-adler32" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" - [[package]] name = "smallvec" version = "1.11.2" @@ -928,12 +592,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "str-buf" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" - [[package]] name = "strsim" version = "0.10.0" @@ -984,37 +642,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "1.0.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.43", -] - -[[package]] -name = "tiff" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211" -dependencies = [ - "flate2", - "jpeg-decoder", - "weezl", -] - [[package]] name = "tui-textarea" version = "0.4.0" @@ -1122,12 +749,6 @@ version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" -[[package]] -name = "weezl" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" - [[package]] name = "winapi" version = "0.3.9" @@ -1144,15 +765,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-wsapoll" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -1300,28 +912,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" -[[package]] -name = "x11rb" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" -dependencies = [ - "gethostname", - "nix", - "winapi", - "winapi-wsapoll", - "x11rb-protocol", -] - -[[package]] -name = "x11rb-protocol" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82d6c3f9a0fb6701fab8f6cea9b0c0bd5d6876f1f89f7fada07e558077c344bc" -dependencies = [ - "nix", -] - [[package]] name = "zerocopy" version = "0.7.32" diff --git a/Cargo.toml b/Cargo.toml index 04e3fe5..5d99a77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,10 @@ edition = "2021" [dependencies] scanf = "1.2.1" sha1 = "0.10.1" -rand = "0.8.5" home = "0.5.9" ratatui = "0.25.0" crossterm = "0.27.0" tui-textarea = "0.4.0" -arboard = "3.3.0" chrono = "0.4.31" clap = { version = "4.4.18", features = ["derive"] } diff --git a/src/fileio.rs b/src/fileio.rs index 5204bcd..5ed2dbe 100644 --- a/src/fileio.rs +++ b/src/fileio.rs @@ -1,4 +1,5 @@ use std::fs::{File, remove_file, remove_dir}; +use std::time::{SystemTime, UNIX_EPOCH}; use std::io::{prelude::*, self}; use std::path::PathBuf; use home::home_dir; @@ -41,7 +42,11 @@ pub fn todo_path() -> io::Result { #[inline(always)] pub fn temp_note_path() -> PathBuf{ - let filename = format!("potato-note.{}", rand::random::()); + let time = match SystemTime::now().duration_since(UNIX_EPOCH) { + Err(_)=>12345, + Ok(some) => some.as_secs(), + }; + let filename = format!("potato-note.{time}"); let path = home_dir().unwrap().join(filename); path.to_path_buf() } diff --git a/src/todo_list/todo.rs b/src/todo_list/todo.rs index ddd958e..5e19954 100644 --- a/src/todo_list/todo.rs +++ b/src/todo_list/todo.rs @@ -131,6 +131,7 @@ impl Todo { self.dependency.is_none() } + #[inline] pub fn remove_note(&mut self) { if self.dependency.is_note() { self.remove_dependency(); @@ -147,6 +148,7 @@ impl Todo { Ok(()) } + #[inline] pub fn remove_dependent_files(&mut self, path: &PathBuf) -> io::Result<()>{ self.dependency.todo_list.handle_dependent_files(path)?; @@ -157,10 +159,12 @@ impl Todo { Ok(()) } + #[inline] pub fn done(&self) -> bool { return self.done } + #[inline] pub fn display(&self, show_done: Option) -> String { let show_done = match show_done { None => true, @@ -181,6 +185,7 @@ impl Todo { format!("{done_string}{}{note_string} {}{daily_str}", self.priority, self.message) } + #[inline] pub fn remove_dependency(&mut self) { if let Some(name) = self.dependency.remove() { self.removed_names.push(name); @@ -189,15 +194,20 @@ impl Todo { self.dependency.todo_list.remove_dependencies(); } + #[inline] pub fn set_note(&mut self, note:String) -> io::Result<()>{ self.dependency = Dependency::new_note(sha1(¬e), note); Ok(()) } + #[inline] pub fn edit_note(&mut self)-> io::Result<()>{ - let note = open_temp_editor(self.dependency.note())?; - self.set_note(note)?; - + if !self.dependency.is_list() { + let note = open_temp_editor(self.dependency.note())?; + if !note.is_empty() { + self.set_note(note)?; + } + } Ok(()) } diff --git a/src/tui/app.rs b/src/tui/app.rs index 1d2a7e2..ecb26f6 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -4,7 +4,6 @@ use std::{io, path::PathBuf}; //}}} // lib{{{ use tui_textarea::{Input, TextArea, CursorMove}; -use arboard::Clipboard; use ratatui::{prelude::*, widgets::*}; use crossterm::event::{self, Event::Key, KeyCode::Char, KeyCode}; // }}} @@ -32,7 +31,7 @@ pub struct App<'a>{ prior_indexes: Vec, text_mode: bool, on_submit: Option()>, - clipboard: Option, + clipboard: String, module_enabled: bool, show_done: bool, search_indexes: Vec, @@ -46,10 +45,7 @@ impl<'a>App<'a>{ #[inline] pub fn new(args:Args,module: &'a mut dyn Module<'a>) -> Self { - let clipboard = match Clipboard::new() { - Ok(some) => Some(some), - Err(_) => None, - }; + let clipboard = String::new(); let todo_path = match args.todo_path { Some(path) => path, None => todo_path().unwrap(), @@ -494,9 +490,7 @@ impl<'a>App<'a>{ let index = self.index; let todo = self.mut_current_list().remove(index); let todo_string:String = (&todo).into(); - if let Some(clipboard) = &mut self.clipboard { - let _ = clipboard.set_text(todo_string); - } + self.clipboard = todo_string; } } @@ -513,28 +507,22 @@ impl<'a>App<'a>{ #[inline] pub fn yank_todo(&mut self) { let todo_string:String = self.todo().unwrap().into(); - if let Some(clipboard) = &mut self.clipboard { - let _ = clipboard.set_text(todo_string); - } + self.clipboard = todo_string; } #[inline] pub fn paste_todo(&mut self) { - if let Some(clipboard) = &mut self.clipboard { - if let Ok(text) = clipboard.get_text() { - match Todo::try_from(text) { - Ok(mut todo) => { - let bottom = self.bottom(); - let todo_parent = TodoList::dependency_parent(&self.todo_path, true); - todo.dependency.read(&todo_parent); - let list = &mut self.mut_current_list(); - list.push(todo); - self.index = list.reorder(bottom); - }, - _ => {}, - }; - } - } + match Todo::try_from(self.clipboard.clone()) { + Ok(mut todo) => { + let bottom = self.bottom(); + let todo_parent = TodoList::dependency_parent(&self.todo_path, true); + todo.dependency.read(&todo_parent); + let list = &mut self.mut_current_list(); + list.push(todo); + self.index = list.reorder(bottom); + }, + _ => {}, + }; } #[inline]