mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat: add Deno.colorDepth
This commit is contained in:
parent
979e2f7158
commit
cce800e3a9
4 changed files with 36 additions and 2 deletions
7
cli/tsc/dts/lib.deno.ns.d.ts
vendored
7
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -500,6 +500,13 @@ declare namespace Deno {
|
|||
*/
|
||||
export const noColor: boolean;
|
||||
|
||||
/**
|
||||
* Get the terminal's color depth.
|
||||
*
|
||||
* @category Runtime
|
||||
*/
|
||||
export const colorDepth: 1 | 4 | 8 | 24;
|
||||
|
||||
/**
|
||||
* Returns the release version of the Operating System.
|
||||
*
|
||||
|
|
|
@ -133,7 +133,7 @@ export class WriteStream extends Socket {
|
|||
// TODO(@marvinhagemeister): Ignore env parameter.
|
||||
// Haven't seen it used anywhere, seems more done
|
||||
// to make testing easier in Node
|
||||
return op_bootstrap_color_depth();
|
||||
return Deno.colorDepth;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import { core, internals, primordials } from "ext:core/mod.js";
|
|||
const ops = core.ops;
|
||||
import {
|
||||
op_bootstrap_args,
|
||||
op_bootstrap_color_depth,
|
||||
op_bootstrap_is_stderr_tty,
|
||||
op_bootstrap_is_stdout_tty,
|
||||
op_bootstrap_no_color,
|
||||
|
@ -599,6 +600,7 @@ ObjectDefineProperties(finalDenoNs, {
|
|||
// https://github.com/denoland/deno/issues/23004
|
||||
ppid: core.propGetterOnly(() => op_ppid()),
|
||||
noColor: core.propGetterOnly(() => op_bootstrap_no_color()),
|
||||
colorDepth: core.propGetterOnly(() => op_bootstrap_color_depth()),
|
||||
args: core.propGetterOnly(opArgs),
|
||||
mainModule: core.propGetterOnly(() => op_main_module()),
|
||||
exitCode: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
import { assertEquals } from "./test_util.ts";
|
||||
import { assert, assertEquals } from "./test_util.ts";
|
||||
|
||||
// Note tests for Deno.stdin.setRaw is in integration tests.
|
||||
|
||||
|
@ -53,3 +53,28 @@ Deno.test(
|
|||
assertEquals(output, "true\n");
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { run: true, read: true } },
|
||||
async function denoColorDepth() {
|
||||
const { stdout } = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "console.log(Deno.colorDepth)"],
|
||||
}).output();
|
||||
const output = new TextDecoder().decode(stdout).trim();
|
||||
assert([1, 4, 8, 24].includes(+output));
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { run: true, read: true } },
|
||||
async function denoColorDepthDisabled() {
|
||||
const { stdout } = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "console.log(Deno.colorDepth)"],
|
||||
env: {
|
||||
NO_COLOR: "1",
|
||||
},
|
||||
}).output();
|
||||
const output = new TextDecoder().decode(stdout).trim();
|
||||
assert([1, 4, 8, 24].includes(+output));
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue