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

73 lines (72 loc) 2.48 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/color.ts var color_exports = {}; __export(color_exports, { getColorLevel: () => getColorLevel, getColorSupport: () => getColorSupport, has256Color: () => has256Color, supportsTrueColor: () => supportsTrueColor }); module.exports = __toCommonJS(color_exports); 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"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getColorLevel, getColorSupport, has256Color, supportsTrueColor }); //# sourceMappingURL=color.js.map