summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRory Dudley2024-02-19 01:04:17 -0700
committerRory Dudley2024-02-19 01:04:17 -0700
commit670f3864e08003b89a362f381a12d509611db870 (patch)
tree0e2121713562ebf082d4e5f93f354bce331f67a5
parent6cf0f1b12e880f3cd88f013a070406bfb303831a (diff)
downloaddwarvish-670f3864e08003b89a362f381a12d509611db870.tar.gz
Refresh paths every loop
Implements the path refresh at the start of each REPL loop. On this commit, it is printing out how long it needed to refresh all the paths in milliseconds.
Notes
Notes: This may be an easier solution than using inotify. There is the obvious downside of a small delay each time we need to print the loop, but the highest I've seen so far is around 12 milliseconds, which seems acceptable. Using inotify as an alternative, it adds quite a few more dependencies, and some overhead in way of a watcher.
-rw-r--r--src/main.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 7fc8991..272eec1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,18 +4,21 @@ use std::io;
use std::io::Write;
use std::path::Path;
use std::process::Command;
+use std::time::SystemTime;
fn eval(paths: &[&str], prompt: &str) {
let mut bins: Vec<String> = Vec::new();
- for path in paths {
- let files = fs::read_dir(path).expect("Unable to read files in your path");
- for file in files {
- bins.push(file.unwrap().path().display().to_string());
+ loop {
+ let now = SystemTime::now();
+ for path in paths {
+ let files = fs::read_dir(path).expect("Unable to read files in your path");
+ for file in files {
+ bins.push(file.unwrap().path().display().to_string());
+ }
}
- }
+ println!("Refresh: {} ms", now.elapsed().unwrap().as_millis());
- loop {
// Output the prompt
io::stdout().flush().unwrap();
print!("{}", prompt);