summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Ogórek <kamil.ogorek@gmail.com>2022-12-19 18:59:32 +0100
committerGitHub <noreply@github.com>2022-12-19 12:59:32 -0500
commit118a35f3bc353cae96bcb29bc96c4f60a7bb1936 (patch)
tree869e7a8044a9b82d597768ba65dcb36e32f6f866
parent2afac5bf78536060a53012c4f938b0390e8827de (diff)
fix(cli): do not clear screen for non-TTY environments in watch mode (#17129)
-rw-r--r--cli/tests/watcher_tests.rs18
-rw-r--r--cli/util/file_watcher.rs4
2 files changed, 13 insertions, 9 deletions
diff --git a/cli/tests/watcher_tests.rs b/cli/tests/watcher_tests.rs
index 06af71eb4..45690d537 100644
--- a/cli/tests/watcher_tests.rs
+++ b/cli/tests/watcher_tests.rs
@@ -8,6 +8,8 @@ use test_util::assert_contains;
use test_util::TempDir;
mod watcher {
+ use util::assert_not_contains;
+
use super::*;
const CLEAR_SCREEN: &str = r#"[2J"#;
@@ -82,7 +84,7 @@ mod watcher {
.lines()
.map(|r| {
let line = r.unwrap();
- eprintln!("STERR: {}", line);
+ eprintln!("STDERR: {}", line);
line
});
(stdout_lines, stderr_lines)
@@ -124,7 +126,7 @@ mod watcher {
let expected = std::fs::read_to_string(badly_linted_output).unwrap();
assert_eq!(output, expected);
- // Change content of the file again to be badly-linted1
+ // Change content of the file again to be badly-linted
std::fs::copy(badly_linted_fixed1, &badly_linted).unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
@@ -132,7 +134,7 @@ mod watcher {
let expected = std::fs::read_to_string(badly_linted_fixed1_output).unwrap();
assert_eq!(output, expected);
- // Change content of the file again to be badly-linted1
+ // Change content of the file again to be badly-linted
std::fs::copy(badly_linted_fixed2, &badly_linted).unwrap();
output = read_all_lints(&mut stderr_lines);
@@ -182,14 +184,14 @@ mod watcher {
let expected = std::fs::read_to_string(badly_linted_output).unwrap();
assert_eq!(output, expected);
- // Change content of the file again to be badly-linted1
+ // Change content of the file again to be badly-linted
std::fs::copy(badly_linted_fixed1, &badly_linted).unwrap();
output = read_all_lints(&mut stderr_lines);
let expected = std::fs::read_to_string(badly_linted_fixed1_output).unwrap();
assert_eq!(output, expected);
- // Change content of the file again to be badly-linted1
+ // Change content of the file again to be badly-linted
std::fs::copy(badly_linted_fixed2, &badly_linted).unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
@@ -425,7 +427,8 @@ mod watcher {
assert_contains!(stderr_lines.next().unwrap(), "Check");
let next_line = stderr_lines.next().unwrap();
- assert_contains!(&next_line, CLEAR_SCREEN);
+ // Should not clear screen, as we are in non-TTY environment
+ assert_not_contains!(&next_line, CLEAR_SCREEN);
assert_contains!(&next_line, "File change detected!");
assert_contains!(stderr_lines.next().unwrap(), "file_to_watch.ts");
assert_contains!(stderr_lines.next().unwrap(), "mod6.bundle.js");
@@ -476,7 +479,8 @@ mod watcher {
assert_contains!(stderr_lines.next().unwrap(), "Check");
let next_line = stderr_lines.next().unwrap();
- assert_contains!(&next_line, CLEAR_SCREEN);
+ // Should not clear screen, as we are in non-TTY environment
+ assert_not_contains!(&next_line, CLEAR_SCREEN);
assert_contains!(&next_line, "File change detected!");
assert_contains!(stderr_lines.next().unwrap(), "file_to_watch.ts");
assert_contains!(stderr_lines.next().unwrap(), "target.js");
diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs
index 5158437a0..b85df3bd6 100644
--- a/cli/util/file_watcher.rs
+++ b/cli/util/file_watcher.rs
@@ -119,13 +119,13 @@ where
pub struct PrintConfig {
/// printing watcher status to terminal.
pub job_name: String,
- /// determine whether to clear the terminal screen
+ /// determine whether to clear the terminal screen; applicable to TTY environments only.
pub clear_screen: bool,
}
fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
move || {
- if clear_screen {
+ if clear_screen && atty::is(atty::Stream::Stderr) {
eprint!("{}", CLEAR_SCREEN);
}
info!(