2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-03-12 15:23:59 -05:00
|
|
|
|
2021-07-06 06:03:12 -04:00
|
|
|
/// <reference path="../../core/internal.d.ts" />
|
|
|
|
|
2021-02-04 17:18:32 -05:00
|
|
|
"use strict";
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
((window) => {
|
2021-07-06 06:03:12 -04:00
|
|
|
const {
|
|
|
|
RegExp,
|
|
|
|
StringPrototypeReplace,
|
|
|
|
ArrayPrototypeJoin,
|
|
|
|
} = window.__bootstrap.primordials;
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
function code(open, close) {
|
|
|
|
return {
|
|
|
|
open: `\x1b[${open}m`,
|
|
|
|
close: `\x1b[${close}m`,
|
|
|
|
regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function run(str, code) {
|
2021-07-06 06:03:12 -04:00
|
|
|
return `${code.open}${
|
|
|
|
StringPrototypeReplace(str, code.regexp, code.open)
|
|
|
|
}${code.close}`;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js
|
|
|
|
const ANSI_PATTERN = new RegExp(
|
2021-07-06 06:03:12 -04:00
|
|
|
ArrayPrototypeJoin([
|
2020-07-19 13:49:44 -04:00
|
|
|
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
|
|
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
2021-07-06 06:03:12 -04:00
|
|
|
], "|"),
|
2020-07-19 13:49:44 -04:00
|
|
|
"g",
|
|
|
|
);
|
|
|
|
|
|
|
|
function stripColor(string) {
|
2021-07-06 06:03:12 -04:00
|
|
|
return StringPrototypeReplace(string, ANSI_PATTERN, "");
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2020-10-15 06:32:03 -04:00
|
|
|
function maybeColor(fn) {
|
|
|
|
return !(globalThis.Deno?.noColor ?? false) ? fn : (s) => s;
|
|
|
|
}
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
window.__bootstrap.colors = {
|
|
|
|
bold,
|
|
|
|
italic,
|
|
|
|
yellow,
|
|
|
|
cyan,
|
|
|
|
red,
|
|
|
|
green,
|
|
|
|
bgRed,
|
|
|
|
white,
|
|
|
|
gray,
|
|
|
|
magenta,
|
|
|
|
stripColor,
|
2020-10-15 06:32:03 -04:00
|
|
|
maybeColor,
|
2020-07-19 13:49:44 -04:00
|
|
|
};
|
|
|
|
})(this);
|