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

135 lines (134 loc) 3.37 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/normalize.ts import path from "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" ? path.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(path.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"); export { AMBIGUOUS_ENV_TERMINALS, SHELL_PROCESS_NAMES, hasKonsoleEnvironment, isAmbiguousEnvResult, normalizeAppName, normalizeIdentifier, normalizeParentProcessName }; //# sourceMappingURL=normalize.mjs.map