summaryrefslogtreecommitdiff
path: root/cli/util/file_watcher.rs
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /cli/util/file_watcher.rs
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'cli/util/file_watcher.rs')
-rw-r--r--cli/util/file_watcher.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs
index d92d880bc..eb3fb8c60 100644
--- a/cli/util/file_watcher.rs
+++ b/cli/util/file_watcher.rs
@@ -30,7 +30,7 @@ use tokio::sync::mpsc;
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::time::sleep;
-const CLEAR_SCREEN: &str = "\x1B[2J\x1B[1;1H";
+const CLEAR_SCREEN: &str = "\x1B[H\x1B[2J\x1B[3J";
const DEBOUNCE_INTERVAL: Duration = Duration::from_millis(200);
struct DebouncedReceiver {
@@ -73,7 +73,6 @@ impl DebouncedReceiver {
}
}
-#[allow(clippy::print_stderr)]
async fn error_handler<F>(watch_future: F) -> bool
where
F: Future<Output = Result<(), AnyError>>,
@@ -84,7 +83,7 @@ where
Some(e) => format_js_error(e),
None => format!("{err:?}"),
};
- eprintln!(
+ log::error!(
"{}: {}",
colors::red_bold("error"),
error_string.trim_start_matches("error: ")
@@ -128,19 +127,12 @@ impl PrintConfig {
}
}
-fn create_print_after_restart_fn(
- banner: &'static str,
- clear_screen: bool,
-) -> impl Fn() {
+fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
move || {
#[allow(clippy::print_stderr)]
if clear_screen && std::io::stderr().is_terminal() {
eprint!("{}", CLEAR_SCREEN);
}
- info!(
- "{} File change detected! Restarting!",
- colors::intense_blue(banner),
- );
}
}
@@ -188,7 +180,15 @@ impl WatcherCommunicator {
}
pub fn print(&self, msg: String) {
- log::info!("{} {}", self.banner, msg);
+ log::info!("{} {}", self.banner, colors::gray(msg));
+ }
+
+ pub fn show_path_changed(&self, changed_paths: Option<Vec<PathBuf>>) {
+ if let Some(paths) = changed_paths {
+ self.print(
+ format!("Restarting! File change detected: {:?}", paths[0]).to_string(),
+ )
+ }
}
}
@@ -264,7 +264,7 @@ where
clear_screen,
} = print_config;
- let print_after_restart = create_print_after_restart_fn(banner, clear_screen);
+ let print_after_restart = create_print_after_restart_fn(clear_screen);
let watcher_communicator = Arc::new(WatcherCommunicator {
paths_to_watch_tx: paths_to_watch_tx.clone(),
changed_paths_rx: changed_paths_rx.resubscribe(),