openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
42 lines (41 loc) • 1.98 kB
JavaScript
import { r as splitGraphemes } from "./ansi-CZa2t0Hf.mjs";
//#region packages/terminal-core/src/decorative-emoji.ts
const EMOJI_GRAPHEME_PATTERN = /[\p{Extended_Pictographic}\p{Regional_Indicator}\u20e3]/u;
/** Detect terminals with known emoji rendering support. */
function isKnownEmojiTerminal(e) {
const t = (e.TERM_PROGRAM ?? "").toLowerCase();
const n = (e.TERM ?? "").toLowerCase();
return t.includes("iterm") || t.includes("apple_terminal") || t.includes("ghostty") || t.includes("wezterm") || t.includes("vscode") || n.includes("ghostty") || n.includes("wezterm") || Boolean(e.WT_SESSION);
}
/** Return true when locale variables indicate UTF-8 output support. */
function hasUtf8Locale(e) {
const t = [
e.LC_ALL,
e.LC_CTYPE,
e.LANG
].find((e) => typeof e === "string" && e.trim().length > 0);
if (!t) return true;
return /utf-?8/i.test(t);
}
/** Return true when decorative emoji should be emitted for the target terminal. */
function supportsDecorativeEmoji(e = {}) {
const t = e.env ?? process.env;
const n = e.platform ?? process.platform;
return e.isTty ?? process.stdout.isTTY ? (t.TERM ?? "").toLowerCase() !== "dumb" && hasUtf8Locale(t) && (isKnownEmojiTerminal(t) || n === "darwin") : false;
}
/** Return the emoji only when decorative emoji output is supported. */
function decorativeEmoji(e, t = {}) {
return supportsDecorativeEmoji(t) ? e : "";
}
/** Prefix text with a decorative emoji when supported. */
function decorativePrefix(e, t, n = {}) {
const r = decorativeEmoji(e, n);
return r ? `${r} ${t}` : t;
}
/** Strip decorative emoji for terminals that should not receive them. */
function stripDecorativeEmojiForTerminal(e, t = {}) {
if (supportsDecorativeEmoji(t)) return e;
return splitGraphemes(e).filter((e) => !EMOJI_GRAPHEME_PATTERN.test(e)).join("").replace(/\s{2,}/g, " ").trim();
}
//#endregion
export { supportsDecorativeEmoji as i, decorativePrefix as n, stripDecorativeEmojiForTerminal as r, decorativeEmoji as t };