1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

feat(repl): add global clear() function (#14332)

This commit adds a clear() function in the REPL which works
similar to console.clear().
This commit is contained in:
Colin Ihrig 2022-04-20 15:48:15 -04:00 committed by GitHub
parent f785ecee1a
commit 2a93c134dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -761,3 +761,21 @@ fn eval_file_flag_multiple_files() {
assert!(out.contains("helloFOO")); assert!(out.contains("helloFOO"));
assert!(err.contains("Download")); 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'));
});
}

View file

@ -41,6 +41,8 @@ Object.defineProperty(globalThis, "_error", {
console.log("Last thrown error is no longer saved to _error."); console.log("Last thrown error is no longer saved to _error.");
}, },
}); });
globalThis.clear = console.clear.bind(console);
"#; "#;
pub enum EvaluationOutput { pub enum EvaluationOutput {