diff options
-rw-r--r-- | Cargo.lock | 61 | ||||
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | src/main.rs | 14 |
3 files changed, 78 insertions, 4 deletions
@@ -270,6 +270,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] +name = "bytes" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" + +[[package]] name = "bytesize" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1916,6 +1922,18 @@ dependencies = [ ] [[package]] +name = "mio" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] name = "nanorand" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2447,6 +2465,7 @@ dependencies = [ "tempfile", "thiserror", "tmux_interface", + "tokio", "toml", "tracing", "tracing-subscriber", @@ -2819,6 +2838,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] name = "spin" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3095,6 +3124,38 @@ dependencies = [ ] [[package]] +name = "tokio" +version = "1.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "parking_lot 0.12.1", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "tracing", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "toml" version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -26,6 +26,13 @@ thiserror = "1.0.37" tmux_interface = { version = "0.2.1", default-features = false, features = [ "tmux_latest", ] } +tokio = { version = "1.23.0", features = [ + "signal", + "tracing", + "macros", + "rt-multi-thread", + "full", +] } tracing = { version = "0.1.37", features = ["attributes"] } tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } diff --git a/src/main.rs b/src/main.rs index 35ae66d..8470651 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,10 @@ use figment::{ Figment, }; use projectr::{project::ProjectItem, search::Search, Cli, Config}; +use tokio::signal; -#[tracing::instrument] -fn main() -> Result<()> { +#[tokio::main] +async fn main() -> Result<()> { let cli = Cli::parse(); let config: Config = Figment::new() @@ -23,11 +24,16 @@ fn main() -> Result<()> { .with_max_level(cli.verbosity) .init(); - run(&config).context("Failed to run projectr") + let res = tokio::select! { + res = signal::ctrl_c() => res.map_err(Into::into), + res = run(&config) => res.context("Failed to run projectr"), + }; + + res } #[tracing::instrument] -pub fn run(config: &Config) -> Result<()> { +pub async fn run(config: &Config) -> Result<()> { let mut projects: Vec<ProjectItem> = Search::from(config.paths.to_owned()).collect(); projects.sort_unstable_by_key(|p| *p.timestamp()); |