From dfe9e7f25ebe75bc42e1ed4384ea98f4ca4ce15e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Feb 2024 12:22:00 +0000 Subject: [PATCH 1/6] Bump chrono from 0.4.33 to 0.4.34 Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.33 to 0.4.34. - [Release notes](https://github.com/chronotope/chrono/releases) - [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md) - [Commits](https://github.com/chronotope/chrono/compare/v0.4.33...v0.4.34) --- updated-dependencies: - dependency-name: chrono dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ff3bfd..7d65830 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,9 +203,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", diff --git a/Cargo.toml b/Cargo.toml index 2aa1a30..a416a98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ categories = [ "command-line-utilities", "gui", "text-processing" ] [dependencies] async-std = "1.12.0" directories = "5.0.1" -chrono = "0.4.33" +chrono = "0.4.34" dialoguer = "0.11.0" inquire = "0.6.2" crossterm = "0.27.0" From 81b4420031666c49fc59fe3c442bc17e37453256 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Feb 2024 12:22:06 +0000 Subject: [PATCH 2/6] Bump rusqlite from 0.30.0 to 0.31.0 Bumps [rusqlite](https://github.com/rusqlite/rusqlite) from 0.30.0 to 0.31.0. - [Release notes](https://github.com/rusqlite/rusqlite/releases) - [Changelog](https://github.com/rusqlite/rusqlite/blob/master/Changelog.md) - [Commits](https://github.com/rusqlite/rusqlite/compare/v0.30.0...v0.31.0) --- updated-dependencies: - dependency-name: rusqlite dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 55 +++++++++++++++++++++++++++++++++++++----------------- Cargo.toml | 2 +- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ff3bfd..c5dd1b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,13 +4,14 @@ version = 3 [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "42cd52102d3df161c77a887b608d7a4897d7cc112886a9537b738a887a03aaff" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -541,9 +542,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash", "allocator-api2", @@ -551,9 +552,9 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.8.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" +checksum = "692eaaf7f7607518dd3cef090f1474b61edc5301d8012f09579920df68b725ee" dependencies = [ "hashbrown", ] @@ -661,7 +662,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.26", + "syn 2.0.32", ] [[package]] @@ -678,9 +679,9 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libsqlite3-sys" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" dependencies = [ "cc", "pkg-config", @@ -933,9 +934,9 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "rusqlite" -version = "0.30.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a78046161564f5e7cd9008aff3b2990b3850dc8e0349119b98e8f251e099f24d" +checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae" dependencies = [ "bitflags 2.3.3", "fallible-iterator", @@ -982,7 +983,7 @@ checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.32", ] [[package]] @@ -1065,9 +1066,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.26" +version = "2.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" dependencies = [ "proc-macro2", "quote", @@ -1121,7 +1122,7 @@ checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.32", ] [[package]] @@ -1193,7 +1194,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.32", "wasm-bindgen-shared", ] @@ -1227,7 +1228,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.32", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1468,6 +1469,26 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 2aa1a30..68c4d72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,5 @@ chrono = "0.4.33" dialoguer = "0.11.0" inquire = "0.6.2" crossterm = "0.27.0" -rusqlite = { version = "0.30.0", features = ["bundled"] } +rusqlite = { version = "0.31.0", features = ["bundled"] } termimad = "0.29.1" From e2acf4f08b66e8b8e8c9566d9f0f8976d89b102d Mon Sep 17 00:00:00 2001 From: ThatBoiDev Date: Mon, 19 Feb 2024 14:26:27 +0100 Subject: [PATCH 3/6] chore: add unit testing --- Cargo.lock | 86 ++++++++++++++++++++++++++++++------------------ Cargo.toml | 1 + src/main.rs | 1 + src/tests/api.rs | 72 ++++++++++++++++++++++++++++++++++++++++ src/tests/mod.rs | 1 + 5 files changed, 129 insertions(+), 32 deletions(-) create mode 100644 src/tests/api.rs create mode 100644 src/tests/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 0ff3bfd..033fdd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,7 @@ dependencies = [ "async-lock", "async-task", "concurrent-queue", - "fastrand", + "fastrand 1.9.0", "futures-lite", "slab", ] @@ -97,7 +97,7 @@ dependencies = [ "log", "parking", "polling", - "rustix", + "rustix 0.37.23", "slab", "socket2", "waker-fn", @@ -164,9 +164,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "blocking" @@ -178,7 +178,7 @@ dependencies = [ "async-lock", "async-task", "atomic-waker", - "fastrand", + "fastrand 1.9.0", "futures-lite", "log", ] @@ -367,7 +367,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.2", "crossterm_winapi", "libc", "mio", @@ -434,23 +434,12 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] @@ -480,6 +469,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "futures-channel" version = "0.3.28" @@ -507,7 +502,7 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ - "fastrand", + "fastrand 1.9.0", "futures-core", "futures-io", "memchr", @@ -672,9 +667,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libsqlite3-sys" @@ -693,6 +688,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + [[package]] name = "lock_api" version = "0.4.10" @@ -768,6 +769,7 @@ dependencies = [ "directories", "inquire", "rusqlite", + "tempfile", "termimad", ] @@ -937,7 +939,7 @@ version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a78046161564f5e7cd9008aff3b2990b3850dc8e0349119b98e8f251e099f24d" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.2", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -955,10 +957,23 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys", + "linux-raw-sys 0.3.8", "windows-sys 0.48.0", ] +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys 0.4.13", + "windows-sys 0.52.0", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1076,16 +1091,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.6.0" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" dependencies = [ - "autocfg", "cfg-if", - "fastrand", - "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.48.0", + "fastrand 2.0.1", + "rustix 0.38.31", + "windows-sys 0.52.0", ] [[package]] @@ -1297,6 +1310,15 @@ dependencies = [ "windows-targets 0.48.1", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.42.2" diff --git a/Cargo.toml b/Cargo.toml index 2aa1a30..3972ec9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ inquire = "0.6.2" crossterm = "0.27.0" rusqlite = { version = "0.30.0", features = ["bundled"] } termimad = "0.29.1" +tempfile = "3.10.0" diff --git a/src/main.rs b/src/main.rs index 592edd3..23b34e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod note; mod prompts; mod return_to_main; mod utilities; +mod tests; use crate::{ note::Note, diff --git a/src/tests/api.rs b/src/tests/api.rs new file mode 100644 index 0000000..68c04af --- /dev/null +++ b/src/tests/api.rs @@ -0,0 +1,72 @@ +#[cfg(test)] +use crate::{api, note::Note}; +use chrono::prelude::Local; +use async_std::path::PathBuf; +use tempfile::tempdir; + +#[test] +fn test_db_init() -> Result<(), Box> { + let dir = tempdir()?; + let data_directory = PathBuf::from(dir.path()); + let db_file = data_directory.join("notes.db"); + assert!(api::init_db(&data_directory, &db_file).is_ok()); + Ok(()) +} + +#[test] +fn test_save_note() -> Result<(), Box> { + let dir = tempdir()?; + let data_directory = PathBuf::from(dir.path()); + let db_file: PathBuf = data_directory.join("notes.db"); + api::init_db(&data_directory, &db_file)?; + + let note = Note { + id: 0, + name: "Test".to_string(), + content: "Test".to_string(), + created: format!("{}", Local::now().format("%A %e %B, %H:%M")), + }; + + assert!(api::save_note(¬e, &db_file).is_ok()); + Ok(()) +} + +#[test] +fn test_delete_notes() { + let dir = tempdir().unwrap(); + let data_directory = PathBuf::from(dir.path()); + let db_file = data_directory.join("notes.db"); + api::init_db(&data_directory, &db_file).unwrap(); + + let note = Note { + id: 0, + name: "Test".to_string(), + content: "Test".to_string(), + created: format!("{}", Local::now().format("%A %e %B, %H:%M")), + }; + + api::save_note(¬e, &db_file).unwrap(); + let notes = api::get_notes(&db_file).unwrap(); + let ids: Vec = notes.iter().map(|note| note.id).collect(); + api::delete_notes(ids, &db_file).unwrap(); + assert!(api::get_notes(&db_file).unwrap().is_empty()); +} + +#[test] +fn test_get_notes() -> Result<(), Box> { + let dir = tempdir()?; + let data_directory = PathBuf::from(dir.path()); + let db_file = data_directory.join("notes.db"); + api::init_db(&data_directory, &db_file)?; + + let note = Note { + id: 0, + name: "Test".to_string(), + content: "Test".to_string(), + created: format!("{}", Local::now().format("%A %e %B, %H:%M")), + }; + + api::save_note(¬e, &db_file)?; + assert!(!api::get_notes(&db_file)?.is_empty()); + Ok(()) +} \ No newline at end of file diff --git a/src/tests/mod.rs b/src/tests/mod.rs new file mode 100644 index 0000000..50123e3 --- /dev/null +++ b/src/tests/mod.rs @@ -0,0 +1 @@ +mod api; \ No newline at end of file From 9eb454f4d0dff43b83d381da97e2002b4f840680 Mon Sep 17 00:00:00 2001 From: ThatBoiDev Date: Mon, 19 Feb 2024 15:02:39 +0100 Subject: [PATCH 4/6] remove unnecessary deps --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3e5e0f9..556094c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ async-std = "1.12.0" directories = "5.0.1" chrono = "0.4.34" dialoguer = "0.11.0" -inquire = "0.6.2" crossterm = "0.27.0" rusqlite = { version = "0.31.0", features = ["bundled"] } termimad = "0.29.1" From 2a401abfacf053b02b694c685b48737d9f031c01 Mon Sep 17 00:00:00 2001 From: ThatBoiDev Date: Mon, 19 Feb 2024 18:26:08 +0100 Subject: [PATCH 5/6] an attempt to fix eturn_to_main (no success) --- Cargo.lock | 62 +++---------------------------------------- src/main.rs | 2 +- src/note.rs | 1 - src/return_to_main.rs | 6 ++--- 4 files changed, 8 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0968c84..3aa719e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,7 +244,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e93977247fb916abeee1ff8c6594c9b421fd9c26c9b720a3944acb2a7de27b" dependencies = [ - "crossterm 0.27.0", + "crossterm", ] [[package]] @@ -260,7 +260,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11650f38fa0dc9fae9b4ac5243c4d32992351f82bb5452c5c1fd7e639057b732" dependencies = [ "crokey-proc_macros", - "crossterm 0.27.0", + "crossterm", "once_cell", "serde", "strict", @@ -272,7 +272,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3588f310d39d0c6f546aaca1e9df18d1dfb961a8bb4042a11b6c5a6b449c1894" dependencies = [ - "crossterm 0.27.0", + "crossterm", "proc-macro2", "quote", "strict", @@ -346,22 +346,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossterm" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" -dependencies = [ - "bitflags 1.3.2", - "crossterm_winapi", - "libc", - "mio", - "parking_lot", - "signal-hook", - "signal-hook-mio", - "winapi", -] - [[package]] name = "crossterm" version = "0.27.0" @@ -421,12 +405,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "dyn-clone" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" - [[package]] name = "encode_unicode" version = "0.3.6" @@ -583,22 +561,6 @@ dependencies = [ "cc", ] -[[package]] -name = "inquire" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c33e7c1ddeb15c9abcbfef6029d8e29f69b52b6d6c891031b88ed91b5065803b" -dependencies = [ - "bitflags 1.3.2", - "crossterm 0.25.0", - "dyn-clone", - "lazy_static", - "newline-converter", - "thiserror", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "instant" version = "0.1.12" @@ -750,25 +712,15 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "newline-converter" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "notabena" version = "0.1.0" dependencies = [ "async-std", "chrono", - "crossterm 0.27.0", + "crossterm", "dialoguer", "directories", - "inquire", "rusqlite", "tempfile", "termimad", @@ -1144,12 +1096,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" diff --git a/src/main.rs b/src/main.rs index 23b34e1..50c24c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use crate::{ note::Note, prompts::{multiselect::multiselect, select::select}, utilities::{cursor_to_origin::cursor_to_origin, truncate_note::truncate_note}, - /* return_to_main::return_to_main, */ + return_to_main::return_to_main }; use async_std::path::PathBuf; use directories::BaseDirs; diff --git a/src/note.rs b/src/note.rs index 75cf186..4d97a56 100644 --- a/src/note.rs +++ b/src/note.rs @@ -41,7 +41,6 @@ impl Note { &inputted_note.created ], )?; - cursor_to_origin()?; println!("Note created successfully."); Ok(()) diff --git a/src/return_to_main.rs b/src/return_to_main.rs index c032748..d6bdf4a 100644 --- a/src/return_to_main.rs +++ b/src/return_to_main.rs @@ -1,5 +1,5 @@ use crossterm::event; -use crossterm::event::{Event, KeyCode, KeyEvent}; +use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use std::time::Duration; @@ -12,8 +12,8 @@ pub fn return_to_main() -> Result<(), Box> { if let Event::Key(event) = event::read()? { match event { KeyEvent { - code: KeyCode::Char('r'), - modifiers: event::KeyModifiers::CONTROL, + code: KeyCode::Char('q'), + modifiers: KeyModifiers::ALT, kind: _, state: _, } => return Ok(()), From e863f6486224e38976da8c3f51c8188678569a07 Mon Sep 17 00:00:00 2001 From: ThatBoiDev Date: Tue, 27 Feb 2024 17:35:15 +0100 Subject: [PATCH 6/6] feat: return key, chore: version increment --- Cargo.lock | 74 ++-------------------------------- Cargo.toml | 4 +- src/main.rs | 4 +- src/note.rs | 61 +++++++++++++--------------- src/prompts/input.rs | 19 ++++++++- src/return_to_main.rs | 37 ++++++++++++----- src/tests/api.rs | 94 +++++++++++++++++++++---------------------- src/tests/mod.rs | 2 +- 8 files changed, 126 insertions(+), 169 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3aa719e..8a11de7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,15 +227,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", "lazy_static", "libc", "unicode-width", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -714,7 +714,7 @@ dependencies = [ [[package]] name = "notabena" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-std", "chrono", @@ -1239,15 +1239,6 @@ dependencies = [ "windows-targets 0.48.1", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -1266,21 +1257,6 @@ dependencies = [ "windows-targets 0.52.0", ] -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-targets" version = "0.48.1" @@ -1311,12 +1287,6 @@ dependencies = [ "windows_x86_64_msvc 0.52.0", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" @@ -1329,12 +1299,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.48.0" @@ -1347,12 +1311,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.48.0" @@ -1365,12 +1323,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.48.0" @@ -1383,12 +1335,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.48.0" @@ -1401,12 +1347,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" @@ -1419,12 +1359,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 556094c..36fb809 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "notabena" -version = "0.1.0" +version = "0.1.1" edition = "2021" -authors = [ "ThatFrogDev", "MrSerge01" ] +authors = [ "ThatFrogDev" ] license-file = "LICENSE.md" description = "A note-taking app for the command line. GUI support will be added (see README)." homepage = "https://github.com/thatfrogdev/notabena" diff --git a/src/main.rs b/src/main.rs index 50c24c4..e3d839c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,14 +2,14 @@ mod api; mod note; mod prompts; mod return_to_main; -mod utilities; mod tests; +mod utilities; use crate::{ note::Note, prompts::{multiselect::multiselect, select::select}, + return_to_main::return_to_main, utilities::{cursor_to_origin::cursor_to_origin, truncate_note::truncate_note}, - return_to_main::return_to_main }; use async_std::path::PathBuf; use directories::BaseDirs; diff --git a/src/note.rs b/src/note.rs index 4d97a56..27c8e49 100644 --- a/src/note.rs +++ b/src/note.rs @@ -1,7 +1,7 @@ use crate::{ api, multiselect, prompts::{confirm::confirm, input::input, select::select}, - truncate_note, + return_to_main, truncate_note, utilities::{cursor_to_origin::cursor_to_origin, display::display}, }; use async_std::path::PathBuf; @@ -19,10 +19,13 @@ pub struct Note { impl Note { pub fn create(db_file: &PathBuf) -> Result<(), Box> { cursor_to_origin()?; + println!( + "If you're done inputting a field, you can press Enter twice to continue or save, or Alt/Option-Q to return to the main menu.\r" + ); let mut inputted_note = Note { id: api::get_notes(db_file)?.len(), - name: input("Name:", "".to_string()), - content: input("Content:", "".to_string()), + name: input("Name:", "".to_string())?, + content: input("Content:", "".to_string())?, created: format!("{}", Local::now().format("%A %e %B, %H:%M")), }; @@ -30,26 +33,18 @@ impl Note { println!("This is the note you're about to create:"); display(&mut inputted_note)?; - match confirm("Do you want to save this note?") { - true => { - Connection::open(db_file)?.execute( - "INSERT INTO saved_notes (id, name, content, created) VALUES (?1, ?2, ?3, ?4);", - params![ - &inputted_note.id, - &inputted_note.name, - &inputted_note.content, - &inputted_note.created - ], - )?; - cursor_to_origin()?; - println!("Note created successfully."); - Ok(()) - } - false => { - cursor_to_origin()?; - Ok(()) - } - } + Connection::open(db_file)?.execute( + "INSERT INTO saved_notes (id, name, content, created) VALUES (?1, ?2, ?3, ?4);", + params![ + &inputted_note.id, + &inputted_note.name, + &inputted_note.content, + &inputted_note.created + ], + )?; + cursor_to_origin()?; + println!("Note created successfully."); + Ok(()) } pub fn show(db_file: &PathBuf) -> Result<(), Box> { @@ -73,6 +68,9 @@ impl Note { pub fn edit(db_file: &PathBuf) -> Result<(), Box> { cursor_to_origin()?; + println!( + "If you're done editing a field, you can press Enter twice to continue or save, or Alt/Option-Q to return to the main menu.\r" + ); let saved_notes = api::get_notes(db_file)?; let mut options: Vec = Vec::new(); truncate_note(&mut options, db_file)?; @@ -80,8 +78,8 @@ impl Note { let selected_note = &saved_notes[selection]; let updated_note = Note { id: selected_note.id.clone(), - name: input("Name:", selected_note.name.clone()), - content: input("Content:", selected_note.content.clone()), + name: input("Name:", selected_note.name.clone())?, + content: input("Content:", selected_note.content.clone())?, created: selected_note.created.clone(), }; @@ -90,15 +88,10 @@ impl Note { println!("You can't edit notes, because there are none."); } - match confirm("Are you sure that you want to edit this note?") { - true => { - cursor_to_origin()?; - api::save_note(&updated_note, db_file)?; // why the fuck whas this line not here yet - println!("Note updated successfully."); - Ok(()) - } - false => Ok(()), - } + cursor_to_origin()?; + api::save_note(&updated_note, db_file)?; // why the fuck whas this line not here yet + println!("Note updated successfully."); + Ok(()) } pub fn delete(db_file: &PathBuf) -> Result<(), Box> { diff --git a/src/prompts/input.rs b/src/prompts/input.rs index c97a3fc..710cf59 100644 --- a/src/prompts/input.rs +++ b/src/prompts/input.rs @@ -1,7 +1,9 @@ +use crate::return_to_main::{continue_event, return_event}; +use crate::{main, return_to_main}; use dialoguer::{theme::ColorfulTheme, Input}; -pub fn input(prompt: &str, initial_text: String) -> String { - match initial_text.as_str() { +pub fn input(prompt: &str, initial_text: String) -> Result> { + let result = match initial_text.as_str() { "" => Input::with_theme(&ColorfulTheme::default()) .with_prompt(prompt) .interact_text() @@ -11,5 +13,18 @@ pub fn input(prompt: &str, initial_text: String) -> String { .with_initial_text(initial_text) .interact_text() .unwrap(), + }; + + match return_to_main() { + Ok(value) => { + if value == return_event() { + main()?; + } else if value == continue_event() { + return Ok(result); + } + } + _ => return Ok(result), } + + Ok(result) } diff --git a/src/return_to_main.rs b/src/return_to_main.rs index d6bdf4a..29e71a4 100644 --- a/src/return_to_main.rs +++ b/src/return_to_main.rs @@ -1,23 +1,38 @@ use crossterm::event; -use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use std::time::Duration; -// TODO: make it not bitch -pub fn return_to_main() -> Result<(), Box> { +// very hacky way to make these values public +pub fn return_event() -> KeyEvent { + KeyEvent { + code: KeyCode::Char('q'), + modifiers: KeyModifiers::ALT, + kind: KeyEventKind::Press, + state: KeyEventState::NONE, + } +} + +pub fn continue_event() -> KeyEvent { + KeyEvent { + code: KeyCode::Enter, + modifiers: KeyModifiers::NONE, + kind: KeyEventKind::Press, + state: KeyEventState::NONE, + } +} + +pub fn return_to_main() -> Result> { enable_raw_mode()?; loop { if event::poll(Duration::from_millis(1000))? { if let Event::Key(event) = event::read()? { - match event { - KeyEvent { - code: KeyCode::Char('q'), - modifiers: KeyModifiers::ALT, - kind: _, - state: _, - } => return Ok(()), - _ => (), + if event == return_event() { + return Ok(return_event()); + } + if event == continue_event() { + return Ok(continue_event()); } } } diff --git a/src/tests/api.rs b/src/tests/api.rs index 68c04af..e70f56e 100644 --- a/src/tests/api.rs +++ b/src/tests/api.rs @@ -1,72 +1,72 @@ #[cfg(test)] use crate::{api, note::Note}; -use chrono::prelude::Local; use async_std::path::PathBuf; +use chrono::prelude::Local; use tempfile::tempdir; #[test] fn test_db_init() -> Result<(), Box> { - let dir = tempdir()?; - let data_directory = PathBuf::from(dir.path()); - let db_file = data_directory.join("notes.db"); - assert!(api::init_db(&data_directory, &db_file).is_ok()); - Ok(()) + let dir = tempdir()?; + let data_directory = PathBuf::from(dir.path()); + let db_file = data_directory.join("notes.db"); + assert!(api::init_db(&data_directory, &db_file).is_ok()); + Ok(()) } #[test] fn test_save_note() -> Result<(), Box> { - let dir = tempdir()?; - let data_directory = PathBuf::from(dir.path()); - let db_file: PathBuf = data_directory.join("notes.db"); - api::init_db(&data_directory, &db_file)?; + let dir = tempdir()?; + let data_directory = PathBuf::from(dir.path()); + let db_file: PathBuf = data_directory.join("notes.db"); + api::init_db(&data_directory, &db_file)?; - let note = Note { - id: 0, - name: "Test".to_string(), - content: "Test".to_string(), - created: format!("{}", Local::now().format("%A %e %B, %H:%M")), - }; + let note = Note { + id: 0, + name: "Test".to_string(), + content: "Test".to_string(), + created: format!("{}", Local::now().format("%A %e %B, %H:%M")), + }; - assert!(api::save_note(¬e, &db_file).is_ok()); - Ok(()) + assert!(api::save_note(¬e, &db_file).is_ok()); + Ok(()) } #[test] fn test_delete_notes() { - let dir = tempdir().unwrap(); - let data_directory = PathBuf::from(dir.path()); - let db_file = data_directory.join("notes.db"); - api::init_db(&data_directory, &db_file).unwrap(); + let dir = tempdir().unwrap(); + let data_directory = PathBuf::from(dir.path()); + let db_file = data_directory.join("notes.db"); + api::init_db(&data_directory, &db_file).unwrap(); - let note = Note { - id: 0, - name: "Test".to_string(), - content: "Test".to_string(), - created: format!("{}", Local::now().format("%A %e %B, %H:%M")), - }; + let note = Note { + id: 0, + name: "Test".to_string(), + content: "Test".to_string(), + created: format!("{}", Local::now().format("%A %e %B, %H:%M")), + }; - api::save_note(¬e, &db_file).unwrap(); - let notes = api::get_notes(&db_file).unwrap(); - let ids: Vec = notes.iter().map(|note| note.id).collect(); - api::delete_notes(ids, &db_file).unwrap(); - assert!(api::get_notes(&db_file).unwrap().is_empty()); + api::save_note(¬e, &db_file).unwrap(); + let notes = api::get_notes(&db_file).unwrap(); + let ids: Vec = notes.iter().map(|note| note.id).collect(); + api::delete_notes(ids, &db_file).unwrap(); + assert!(api::get_notes(&db_file).unwrap().is_empty()); } #[test] fn test_get_notes() -> Result<(), Box> { - let dir = tempdir()?; - let data_directory = PathBuf::from(dir.path()); - let db_file = data_directory.join("notes.db"); - api::init_db(&data_directory, &db_file)?; + let dir = tempdir()?; + let data_directory = PathBuf::from(dir.path()); + let db_file = data_directory.join("notes.db"); + api::init_db(&data_directory, &db_file)?; - let note = Note { - id: 0, - name: "Test".to_string(), - content: "Test".to_string(), - created: format!("{}", Local::now().format("%A %e %B, %H:%M")), - }; + let note = Note { + id: 0, + name: "Test".to_string(), + content: "Test".to_string(), + created: format!("{}", Local::now().format("%A %e %B, %H:%M")), + }; - api::save_note(¬e, &db_file)?; - assert!(!api::get_notes(&db_file)?.is_empty()); - Ok(()) -} \ No newline at end of file + api::save_note(¬e, &db_file)?; + assert!(!api::get_notes(&db_file)?.is_empty()); + Ok(()) +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 50123e3..b32f9e2 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1 +1 @@ -mod api; \ No newline at end of file +mod api;