mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix(runtime): fix Deno.noColor when stdout is not tty (#21208)
This commit is contained in:
parent
4913274a65
commit
c67de43ff3
3 changed files with 22 additions and 4 deletions
|
@ -13,3 +13,14 @@ Deno.test(
|
|||
assertEquals(output, "1\n");
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { run: true, read: true } },
|
||||
async function denoNoColorIsNotAffectedByNonTty() {
|
||||
const { stdout } = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "console.log(Deno.noColor)"],
|
||||
}).output();
|
||||
const output = new TextDecoder().decode(stdout);
|
||||
assertEquals(output, "false\n");
|
||||
},
|
||||
);
|
||||
|
|
|
@ -241,7 +241,7 @@ function opMainModule() {
|
|||
const opArgs = memoizeLazy(() => ops.op_bootstrap_args());
|
||||
const opPid = memoizeLazy(() => ops.op_bootstrap_pid());
|
||||
const opPpid = memoizeLazy(() => ops.op_ppid());
|
||||
setNoColorFn(() => ops.op_bootstrap_no_color());
|
||||
setNoColorFn(() => ops.op_bootstrap_no_color() || !ops.op_bootstrap_is_tty());
|
||||
|
||||
function formatException(error) {
|
||||
if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, error)) {
|
||||
|
@ -530,7 +530,7 @@ function bootstrapMainRuntime(runtimeOptions) {
|
|||
ObjectDefineProperties(finalDenoNs, {
|
||||
pid: util.getterOnly(opPid),
|
||||
ppid: util.getterOnly(opPpid),
|
||||
noColor: util.getterOnly(getNoColor),
|
||||
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
|
||||
args: util.getterOnly(opArgs),
|
||||
mainModule: util.getterOnly(opMainModule),
|
||||
});
|
||||
|
@ -666,7 +666,7 @@ function bootstrapWorkerRuntime(
|
|||
}
|
||||
ObjectDefineProperties(finalDenoNs, {
|
||||
pid: util.getterOnly(opPid),
|
||||
noColor: util.getterOnly(getNoColor),
|
||||
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
|
||||
args: util.getterOnly(opArgs),
|
||||
});
|
||||
// Setup `Deno` global - we're actually overriding already
|
||||
|
|
|
@ -15,6 +15,7 @@ deno_core::extension!(
|
|||
op_bootstrap_language,
|
||||
op_bootstrap_log_level,
|
||||
op_bootstrap_no_color,
|
||||
op_bootstrap_is_tty,
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -57,5 +58,11 @@ pub fn op_bootstrap_log_level(state: &mut OpState) -> i32 {
|
|||
#[op2(fast)]
|
||||
pub fn op_bootstrap_no_color(state: &mut OpState) -> bool {
|
||||
let options = state.borrow::<BootstrapOptions>();
|
||||
options.no_color || !options.is_tty
|
||||
options.no_color
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_bootstrap_is_tty(state: &mut OpState) -> bool {
|
||||
let options = state.borrow::<BootstrapOptions>();
|
||||
options.is_tty
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue