Skip to content

Commit

Permalink
Add Ctrl/Cmd+C support (#14)
Browse files Browse the repository at this point in the history
* Add support for Ctrl/Cmd+C to cancel and exit.
  • Loading branch information
emilevr authored Feb 15, 2024
1 parent 52515fb commit abb0cfb
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 51 deletions.
124 changes: 106 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ anyhow = "^1.0.72"
clap = { version = "=4.4.6", optional = true }
criterion = { version = "^0.5.1", default-features = false, features = [], optional = true }
crossterm = { version = "^0.27.0", optional = true }
ctrlc = { version = "3.4.2", features = ["termination"] }
dirs = { version = "^5.0.1", optional = true }
log = { version = "^0.4.20", optional = true }
log4rs = { version = "^1.2.0", optional = true }
Expand Down
9 changes: 7 additions & 2 deletions benches/directory_item_build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use space_rs::DirectoryItem;
use std::path::Path;
use std::{
path::Path,
sync::{atomic::AtomicBool, Arc},
};

const DIRECTORY_PATH: &str = "./tmp.sample";

pub fn directory_item_build(c: &mut Criterion) {
let path = &Path::new(DIRECTORY_PATH).to_path_buf();
let should_exit = Arc::new(AtomicBool::new(false));

c.bench_function(
&format!("DirectoryItem::build() on {}", path.display()),
|b| {
b.iter(|| {
black_box(DirectoryItem::build(vec![path.clone()]));
black_box(DirectoryItem::build(vec![path.clone()], &should_exit));
})
},
);
Expand Down
9 changes: 7 additions & 2 deletions benches/directory_item_build_x2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use space_rs::DirectoryItem;
use std::path::Path;
use std::{
path::Path,
sync::{atomic::AtomicBool, Arc},
};

const DIRECTORY_PATH: &str = "./tmp.sample";

Expand All @@ -16,11 +19,13 @@ pub fn directory_item_build_x2(c: &mut Criterion) {
.build_global()
.unwrap();

let should_exit = Arc::new(AtomicBool::new(false));

c.bench_function(
&format!("DirectoryItem::build() x2 on {}", path.display()),
|b| {
b.iter(|| {
black_box(DirectoryItem::build(vec![path.clone()]));
black_box(DirectoryItem::build(vec![path.clone()], &should_exit));
})
},
);
Expand Down
Loading

0 comments on commit abb0cfb

Please sign in to comment.