update deno commons
This commit is contained in:
@@ -247,7 +247,7 @@ interface ColorToken {
|
||||
color?: string;
|
||||
}
|
||||
|
||||
function parseColorTokens(message: string): ColorToken[] {
|
||||
function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
const tokens: ColorToken[] = [];
|
||||
if (message) {
|
||||
let inColorStart = false;
|
||||
@@ -372,6 +372,21 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
||||
return text.join("");
|
||||
}
|
||||
|
||||
export function supportColor(): boolean {
|
||||
try {
|
||||
if (process.env.FORCE_COLOR !== undefined) {
|
||||
return process.env.FORCE_COLOR !== "0";
|
||||
}
|
||||
if (process.env.NO_COLOR !== undefined) {
|
||||
return false;
|
||||
}
|
||||
return process.stdout.isTTY && process.stderr.isTTY;
|
||||
} catch (e) {
|
||||
// check color support failed, default false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class Term {
|
||||
constructor() {
|
||||
}
|
||||
@@ -412,8 +427,11 @@ class Term {
|
||||
return `\x1b[36m${message}\x1b[0m`;
|
||||
}
|
||||
|
||||
auto(message: string): string {
|
||||
return renderColorTokens(parseColorTokens(message));
|
||||
auto(message: string, renderColor?: boolean): string {
|
||||
return renderColorTokens(
|
||||
parseColorTokens(message),
|
||||
renderColor ?? supportColor(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user