summaryrefslogtreecommitdiff
path: root/ext/console
diff options
context:
space:
mode:
Diffstat (limited to 'ext/console')
-rw-r--r--ext/console/01_colors.js108
-rw-r--r--ext/console/01_console.js (renamed from ext/console/02_console.js)17
-rw-r--r--ext/console/internal.d.ts2
-rw-r--r--ext/console/lib.rs2
4 files changed, 16 insertions, 113 deletions
diff --git a/ext/console/01_colors.js b/ext/console/01_colors.js
deleted file mode 100644
index a598db921..000000000
--- a/ext/console/01_colors.js
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-
-/// <reference path="../../core/internal.d.ts" />
-
-const primordials = globalThis.__bootstrap.primordials;
-const {
- SafeRegExp,
- StringPrototypeReplace,
- ArrayPrototypeJoin,
-} = primordials;
-
-let noColor = false;
-
-function setNoColor(value) {
- noColor = value;
-}
-
-function getNoColor() {
- return noColor;
-}
-
-function code(open, close) {
- return {
- open: `\x1b[${open}m`,
- close: `\x1b[${close}m`,
- regexp: new SafeRegExp(`\\x1b\\[${close}m`, "g"),
- };
-}
-
-function run(str, code) {
- return `${code.open}${
- StringPrototypeReplace(str, code.regexp, code.open)
- }${code.close}`;
-}
-
-function bold(str) {
- return run(str, code(1, 22));
-}
-
-function italic(str) {
- return run(str, code(3, 23));
-}
-
-function yellow(str) {
- return run(str, code(33, 39));
-}
-
-function cyan(str) {
- return run(str, code(36, 39));
-}
-
-function red(str) {
- return run(str, code(31, 39));
-}
-
-function green(str) {
- return run(str, code(32, 39));
-}
-
-function bgRed(str) {
- return run(str, code(41, 49));
-}
-
-function white(str) {
- return run(str, code(37, 39));
-}
-
-function gray(str) {
- return run(str, code(90, 39));
-}
-
-function magenta(str) {
- return run(str, code(35, 39));
-}
-
-// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
-const ANSI_PATTERN = new SafeRegExp(
- ArrayPrototypeJoin([
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
- ], "|"),
- "g",
-);
-
-function stripColor(string) {
- return StringPrototypeReplace(string, ANSI_PATTERN, "");
-}
-
-function maybeColor(fn) {
- return !noColor ? fn : (s) => s;
-}
-
-export {
- bgRed,
- bold,
- cyan,
- getNoColor,
- gray,
- green,
- italic,
- magenta,
- maybeColor,
- red,
- setNoColor,
- stripColor,
- white,
- yellow,
-};
diff --git a/ext/console/02_console.js b/ext/console/01_console.js
index 51e827876..318cf9cb4 100644
--- a/ext/console/02_console.js
+++ b/ext/console/01_console.js
@@ -119,7 +119,16 @@ const {
SafeMapIterator,
ArrayBufferPrototype,
} = primordials;
-import * as colors_ from "ext:deno_console/01_colors.js";
+
+let noColor = false;
+
+function setNoColor(value) {
+ noColor = value;
+}
+
+function getNoColor() {
+ return noColor;
+}
// Don't use 'blue' not visible on cmd.exe
const styles = {
@@ -3031,7 +3040,7 @@ function inspectArgs(args, inspectOptions = {}) {
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
if (ctx.maxStringLength === null) ctx.maxStringLength = Infinity;
- const noColor = colors_.getNoColor();
+ const noColor = getNoColor();
const first = args[0];
let a = 0;
let string = "";
@@ -3146,7 +3155,7 @@ const timerMap = new SafeMap();
const isConsoleInstance = Symbol("isConsoleInstance");
function getConsoleInspectOptions() {
- const color = !colors_.getNoColor();
+ const color = !getNoColor();
return {
...getDefaultInspectOptions(),
colors: color,
@@ -3597,9 +3606,11 @@ export {
formatNumber,
formatValue,
getDefaultInspectOptions,
+ getNoColor,
inspect,
inspectArgs,
quoteString,
+ setNoColor,
styles,
wrapConsole,
};
diff --git a/ext/console/internal.d.ts b/ext/console/internal.d.ts
index d344f3a77..1fbc89378 100644
--- a/ext/console/internal.d.ts
+++ b/ext/console/internal.d.ts
@@ -3,7 +3,7 @@
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
-declare module "ext:deno_console/02_console.js" {
+declare module "ext:deno_console/01_console.js" {
function createFilteredInspectProxy<TObject>(params: {
object: TObject;
keys: (keyof TObject)[];
diff --git a/ext/console/lib.rs b/ext/console/lib.rs
index a45b856cd..a31470e08 100644
--- a/ext/console/lib.rs
+++ b/ext/console/lib.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::path::PathBuf;
-deno_core::extension!(deno_console, esm = ["01_colors.js", "02_console.js"],);
+deno_core::extension!(deno_console, esm = ["01_console.js"],);
pub fn get_declaration() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts")