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

136 lines (133 loc) 4.27 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/shell.ts var shell_exports = {}; __export(shell_exports, { detectFromShell: () => detectFromShell, detectFromShellResult: () => detectFromShellResult }); module.exports = __toCommonJS(shell_exports); var import_node_child_process = require("child_process"); // src/normalize.ts var import_node_path = __toESM(require("path")); var normalizeIdentifier = /* @__PURE__ */ __name((value) => { return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_"); }, "normalizeIdentifier"); // src/shell.ts var runShellTerm = /* @__PURE__ */ __name((run) => { return run("sh", ["-c", 'printf %s "$TERM"'], { encoding: "utf8", timeout: 1e3, stdio: ["ignore", "pipe", "ignore"] }); }, "runShellTerm"); var detectFromShellResult = /* @__PURE__ */ __name((options = {}) => { const env = options.env ?? process.env; const platform = options.platform ?? process.platform; try { if (platform === "win32") { if (env.WT_SESSION) { return { terminal: "windows_terminal", source: "shell" }; } const shell = env.COMSPEC?.toLowerCase() || ""; if (/powershell/i.test(shell)) { return { terminal: "powershell", source: "shell" }; } if (/pwsh/i.test(shell)) { return { terminal: "powershell", source: "shell" }; } if (/cmd\.exe/i.test(shell)) { return { terminal: "cmd", source: "shell" }; } if (/wt\.exe/i.test(shell)) { return { terminal: "windows_terminal", source: "shell" }; } if (/conhost\.exe/i.test(shell)) { return { terminal: "conhost", source: "shell" }; } return { terminal: "windows_cmd", source: "shell" }; } const run = options.execFileSync ?? import_node_child_process.execFileSync; const terminal = normalizeIdentifier(runShellTerm(run)); if (!terminal) { return null; } if (!options.preferOuter) { if (terminal.startsWith("tmux")) { return { terminal: "tmux", source: "shell" }; } if (terminal.startsWith("screen")) { return { terminal: "screen", source: "shell" }; } } return { terminal, source: "shell" }; } catch { return null; } }, "detectFromShellResult"); var detectFromShell = /* @__PURE__ */ __name((options = {}) => { return detectFromShellResult(options)?.terminal ?? null; }, "detectFromShell"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { detectFromShell, detectFromShellResult }); //# sourceMappingURL=shell.js.map