mirror of
https://github.com/denoland/deno.git
synced 2025-01-05 05:49:20 -05:00
refactor: use primordials for extensions/console (#11249)
This commit is contained in:
parent
ab6b0cefd3
commit
2ed222fceb
2 changed files with 380 additions and 185 deletions
|
@ -1,8 +1,16 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
/// <reference path="../../core/internal.d.ts" />
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
|
const {
|
||||||
|
RegExp,
|
||||||
|
StringPrototypeReplace,
|
||||||
|
ArrayPrototypeJoin,
|
||||||
|
} = window.__bootstrap.primordials;
|
||||||
|
|
||||||
function code(open, close) {
|
function code(open, close) {
|
||||||
return {
|
return {
|
||||||
open: `\x1b[${open}m`,
|
open: `\x1b[${open}m`,
|
||||||
|
@ -12,7 +20,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(str, code) {
|
function run(str, code) {
|
||||||
return `${code.open}${str.replace(code.regexp, code.open)}${code.close}`;
|
return `${code.open}${
|
||||||
|
StringPrototypeReplace(str, code.regexp, code.open)
|
||||||
|
}${code.close}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bold(str) {
|
function bold(str) {
|
||||||
|
@ -57,15 +67,15 @@
|
||||||
|
|
||||||
// https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js
|
// https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js
|
||||||
const ANSI_PATTERN = new RegExp(
|
const ANSI_PATTERN = new RegExp(
|
||||||
[
|
ArrayPrototypeJoin([
|
||||||
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
||||||
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
||||||
].join("|"),
|
], "|"),
|
||||||
"g",
|
"g",
|
||||||
);
|
);
|
||||||
|
|
||||||
function stripColor(string) {
|
function stripColor(string) {
|
||||||
return string.replace(ANSI_PATTERN, "");
|
return StringPrototypeReplace(string, ANSI_PATTERN, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeColor(fn) {
|
function maybeColor(fn) {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue