'use strict'; var process = require('process'); var tty = require('tty'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var process__default = /*#__PURE__*/_interopDefault(process); var tty__default = /*#__PURE__*/_interopDefault(tty); // src/env.ts function getRuntimeConfig(mockGlobal) { const _global = mockGlobal || globalThis; const Deno = _global.Deno; const Bun = _global.Bun; const isDeno = Deno != null; const isBun = Bun != null; const proc = _global.process || Deno || {}; let env = proc.env || {}; if (isDeno) { try { env = Deno.env.toObject(); } catch { env = {}; } } return { env, isTTY: isDeno ? Deno.isatty(1) : !!proc.stdout?.isTTY, platform: isDeno ? Deno.build.os : proc.platform, argv: proc.argv || proc.args || [], runtime: isDeno ? "deno" : isBun ? "bun" : "node" }; } // src/supports.ts var SPACE_MONO = 0; var SPACE_16_COLORS = 1; var SPACE_256_COLORS = 2; var SPACE_TRUE_COLORS = 3; function hasFlag(argv, regex) { return !!argv.find((arg) => regex.test(arg)); } function getColorSpace(mockGlobal) { let colorSpace = -1; const runtime = getRuntimeConfig(mockGlobal); if (runtime.runtime === "deno" && Object.keys(runtime.env).length === 0) { colorSpace = SPACE_MONO; } const FORCE_COLOR = "FORCE_COLOR"; const forceColorValue = runtime.env[FORCE_COLOR]; const forceColorNum = Number.parseInt(forceColorValue); const forceColor = forceColorValue === "false" ? SPACE_MONO : Number.isNaN(forceColorNum) ? SPACE_TRUE_COLORS : forceColorNum; const isForceDisabled = "NO_COLOR" in runtime.env || forceColor === SPACE_MONO || hasFlag(runtime.argv, /^-{1,2}(?:no-color|color=(?:false|never))$/); const isForceEnabled = FORCE_COLOR in runtime.env && forceColor || hasFlag(runtime.argv, /^-{1,2}color=?(?:true|always)?$/); if (isForceDisabled) return SPACE_MONO; if (colorSpace < 0) { colorSpace = getColorSpaceByRuntime( runtime.env, runtime.isTTY, runtime.platform === "win32" ); } return isForceEnabled && colorSpace === SPACE_MONO ? SPACE_TRUE_COLORS : colorSpace; } var TRUE_COLOR_CI = [ "GITHUB_ACTIONS", "GITEA_ACTIONS" ]; function getColorSpaceByRuntime(env, isTTY, isWin) { const { TERM, COLORTERM } = env; if ("TF_BUILD" in env) return SPACE_16_COLORS; if ("TEAMCITY_VERSION" in env) return SPACE_256_COLORS; if ("CI" in env) { if (TRUE_COLOR_CI.some((key) => key in env)) return SPACE_TRUE_COLORS; return SPACE_16_COLORS; } if (!isTTY || /-mono|dumb/i.test(TERM)) return SPACE_MONO; if (isWin) return SPACE_TRUE_COLORS; if (COLORTERM === "truecolor" || COLORTERM === "24bit") return SPACE_TRUE_COLORS; if (TERM === "xterm-kitty") return SPACE_TRUE_COLORS; if (/-256(?:colou?r)?$/i.test(TERM)) return SPACE_256_COLORS; if (/^screen|^tmux|^xterm|^vt[1-5]\d\d?|^ansi|color|cygwin|linux|mintty|rxvt/i.test(TERM)) return SPACE_16_COLORS; return SPACE_TRUE_COLORS; } function isTrueColorSupported(mockGlobal) { return getColorSpace(mockGlobal) === SPACE_TRUE_COLORS; } function is256ColorSupported(mockGlobal) { return getColorSpace(mockGlobal) >= SPACE_256_COLORS; } function is16ColorSupported(mockGlobal) { return getColorSpace(mockGlobal) >= SPACE_16_COLORS; } function isColorsSupported(mockGlobal) { return getColorSpace(mockGlobal) > SPACE_MONO; } function isUnicodeSupported() { if (process__default.default.platform === "win32") { return Boolean(process__default.default.env.CI) || Boolean(process__default.default.env.WT_SESSION) || process__default.default.env.TERM_PROGRAM === "vscode" || process__default.default.env.TERM === "xterm-256color" || process__default.default.env.TERM === "alacritty"; } if (!tty__default.default.isatty(1)) { return false; } if (process__default.default.env.TERM === "dumb") { return false; } if (process__default.default.platform === "darwin") { return true; } if (process__default.default.env.TERM && ["xterm", "xterm-256color", "xterm-color", "screen", "screen-256color", "tmux", "tmux-256color"].includes(process__default.default.env.TERM)) { return true; } return Boolean(process__default.default.env.LANG && process__default.default.env.LANG.includes("UTF-8")); } // src/utils.ts var RESET = "\x1B[2J\x1B[0;0H"; var ERASE_SCREEN = "\x1B[2J"; var ERASE_SCREEN_LEFT = "\x1B[1J"; var ERASE_SCREEN_RIGHT = "\x1B[J"; var ERASE_LINE = "\x1B[2K"; var ERASE_LINE_LEFT = "\x1B[1K"; var ERASE_LINE_RIGHT = "\x1B[K"; var ANSI_REGEX = /[\u001B\u009B][[\]()#;?]*(?:(?:(?:;[-\w/#&.:=?%@~]+)+|[a-zA-Z\d]+(?:;[-\w/#&.:=?%@~]*)*)?\u0007|(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~])/g; function strip(text) { return text.replace(ANSI_REGEX, ""); } function getWindowSize(fallback = { height: 0, width: 0 }) { return { width: process__default.default.stdout.columns || fallback.width || 0, height: process__default.default.stdout.rows || fallback.height || 0 }; } exports.ANSI_REGEX = ANSI_REGEX; exports.ERASE_LINE = ERASE_LINE; exports.ERASE_LINE_LEFT = ERASE_LINE_LEFT; exports.ERASE_LINE_RIGHT = ERASE_LINE_RIGHT; exports.ERASE_SCREEN = ERASE_SCREEN; exports.ERASE_SCREEN_LEFT = ERASE_SCREEN_LEFT; exports.ERASE_SCREEN_RIGHT = ERASE_SCREEN_RIGHT; exports.RESET = RESET; exports.SPACE_16_COLORS = SPACE_16_COLORS; exports.SPACE_256_COLORS = SPACE_256_COLORS; exports.SPACE_MONO = SPACE_MONO; exports.SPACE_TRUE_COLORS = SPACE_TRUE_COLORS; exports.getColorSpace = getColorSpace; exports.getRuntimeConfig = getRuntimeConfig; exports.getWindowSize = getWindowSize; exports.is16ColorSupported = is16ColorSupported; exports.is256ColorSupported = is256ColorSupported; exports.isColorsSupported = isColorsSupported; exports.isTrueColorSupported = isTrueColorSupported; exports.isUnicodeSupported = isUnicodeSupported; exports.strip = strip;