UNPKG

detect-terminal

Version:

Detect the terminal program currently being used, with support for iTerm, Terminal.app, Hyper, iTerm2, ConEmu, Cmde,r Alacritty, Xterm, Terminator, Termux, Kitty, and others. Detection is based on environment variables and process-level indicators to iden

47 lines (46 loc) 1.38 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/color.ts var TRUE_COLOR_PATTERN = /^(truecolor|24bits?)$/; var has256Color = /* @__PURE__ */ __name((value) => { return Boolean(value?.match(/256/)); }, "has256Color"); var supportsTrueColor = /* @__PURE__ */ __name((value) => { return Boolean(value?.match(TRUE_COLOR_PATTERN)); }, "supportsTrueColor"); var getColorSupport = /* @__PURE__ */ __name((env) => { return { supports256Color: has256Color(env.TERM) || has256Color(env.COLORTERM), supportsTrueColor: supportsTrueColor(env.COLORTERM) }; }, "getColorSupport"); var NO_BASIC_COLOR_TERMINALS = /* @__PURE__ */ new Set([ "dumb", "linux_console", "none", "unknown", "vt100" ]); var getColorLevel = /* @__PURE__ */ __name((env, terminal, colorSupport = getColorSupport(env)) => { const { supports256Color, supportsTrueColor: supportsTrueColor2 } = colorSupport; if (supportsTrueColor2) { return 3; } if (supports256Color) { return 2; } if (terminal && !NO_BASIC_COLOR_TERMINALS.has(terminal)) { return 1; } if (env.TERM_PROGRAM || env.COLORTERM || env.TERMUX_VERSION) { return 1; } return 0; }, "getColorLevel"); export { getColorLevel, getColorSupport, has256Color, supportsTrueColor }; //# sourceMappingURL=color.mjs.map