diff options
author | Colin Ihrig <cjihrig@gmail.com> | 2022-04-20 15:48:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 15:48:15 -0400 |
commit | 2a93c134dc93d70b5f6ea9d417c88207661884d5 (patch) | |
tree | 09fecb2f1c44da117309e2ad436ffa56860c9b6e | |
parent | f785ecee1a68faac517a6d35763dd26ef033d722 (diff) |
feat(repl): add global clear() function (#14332)
This commit adds a clear() function in the REPL which works
similar to console.clear().
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 18 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index a63be3ece..05a17d4b7 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -761,3 +761,21 @@ fn eval_file_flag_multiple_files() { assert!(out.contains("helloFOO")); assert!(err.contains("Download")); } + +#[test] +fn pty_clear_function() { + util::with_pty(&["repl"], |mut console| { + console.write_line("console.log('hello');"); + console.write_line("clear();"); + console.write_line("const clear = 1 + 2;"); + console.write_line("clear;"); + console.write_line("close();"); + + let output = console.read_all_output(); + assert!(output.contains("hello")); + assert!(output.contains("[1;1H")); + assert!(output.contains("undefined")); + assert!(output.contains("const clear = 1 + 2;")); + assert!(output.contains('3')); + }); +} diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 57109eb1d..d72fc9499 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -41,6 +41,8 @@ Object.defineProperty(globalThis, "_error", { console.log("Last thrown error is no longer saved to _error."); }, }); + +globalThis.clear = console.clear.bind(console); "#; pub enum EvaluationOutput { |