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
174 lines (173 loc) • 5.35 kB
JavaScript
;
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/normalize.ts
var normalize_exports = {};
__export(normalize_exports, {
AMBIGUOUS_ENV_TERMINALS: () => AMBIGUOUS_ENV_TERMINALS,
SHELL_PROCESS_NAMES: () => SHELL_PROCESS_NAMES,
hasKonsoleEnvironment: () => hasKonsoleEnvironment,
isAmbiguousEnvResult: () => isAmbiguousEnvResult,
normalizeAppName: () => normalizeAppName,
normalizeIdentifier: () => normalizeIdentifier,
normalizeParentProcessName: () => normalizeParentProcessName
});
module.exports = __toCommonJS(normalize_exports);
var import_node_path = __toESM(require("path"));
var AMBIGUOUS_ENV_TERMINALS = /* @__PURE__ */ new Set([
"linux_console",
"truecolor_terminal",
"vt100",
"xterm",
"xterm_256color",
"xterm_truecolor"
]);
var SHELL_PROCESS_NAMES = /* @__PURE__ */ new Set([
"bash",
"csh",
"dash",
"fish",
"ksh",
"login",
"node",
"nodejs",
"nu",
"sh",
"sudo",
"tcsh",
"zsh"
]);
var normalizeIdentifier = /* @__PURE__ */ __name((value) => {
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_");
}, "normalizeIdentifier");
var normalizeAppName = /* @__PURE__ */ __name((value, platform) => {
const appName = platform === "darwin" ? import_node_path.default.parse(value).name : value;
return normalizeIdentifier(appName);
}, "normalizeAppName");
var isAmbiguousEnvResult = /* @__PURE__ */ __name((terminal, options = {}) => {
if (!terminal) {
return true;
}
if (options.preferOuter && (terminal === "tmux" || terminal === "screen")) {
return true;
}
return AMBIGUOUS_ENV_TERMINALS.has(terminal);
}, "isAmbiguousEnvResult");
var hasKonsoleEnvironment = /* @__PURE__ */ __name((env) => {
return Object.keys(env).some((envVar) => /konsole/i.test(envVar));
}, "hasKonsoleEnvironment");
var normalizeParentProcessName = /* @__PURE__ */ __name((processName) => {
const normalized = normalizeIdentifier(import_node_path.default.parse(processName).name);
switch (normalized) {
case "alacritty":
case "aterm":
case "atomic_terminal":
case "eterm":
case "foot":
case "ghostty":
case "hyper":
case "kitty":
case "konsole":
case "kuake":
case "mate_terminal":
case "mrxvt":
case "powershell":
case "putty":
case "qterminal":
case "rio":
case "rxvt":
case "terminator":
case "terminology":
case "tilda":
case "tmux":
case "warp":
case "wezterm":
case "wterm":
return normalized;
case "apple_terminal":
case "terminal":
return "terminal";
case "cmd":
return "cmd";
case "code":
case "code_insiders":
return "vscode";
case "conhost":
return "conhost";
case "gnome":
case "gnome_terminal":
case "gnome_terminal_server":
case "guake":
return "gnome_terminal";
case "iterm":
case "iterm2":
return "iterm";
case "login":
case "linux":
return "linux_console";
case "pwsh":
return "powershell";
case "screen":
return "screen";
case "terminal_app":
return "terminal_app";
case "urxvt":
case "urxvt256c":
case "urxvt256c_ml":
case "urxvt_ml":
return "rxvt";
case "wt":
case "windows_terminal":
return "windows_terminal";
case "xfce":
case "xfce_terminal":
case "xfce4_terminal":
return "xfce4_terminal";
default: {
if (normalized.startsWith("gnome_terminal")) {
return "gnome_terminal";
}
if (normalized.startsWith("warp")) {
return "warp";
}
return null;
}
}
}, "normalizeParentProcessName");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AMBIGUOUS_ENV_TERMINALS,
SHELL_PROCESS_NAMES,
hasKonsoleEnvironment,
isAmbiguousEnvResult,
normalizeAppName,
normalizeIdentifier,
normalizeParentProcessName
});
//# sourceMappingURL=normalize.js.map