Versions 2 to 318
new file, 70 lines
7+
9+export function colorsPass(stream: { isTTY?: boolean }, env: Readonly<Record<string, string | undefined>>): boolean {
12+
13+/** The length of the SGR sequence (ESC [ digits ; : m) starting at i, or 0 when there isn't one. */
23+
25+ * An SGR sequence without parameter 8 (conceal), which would hide the text after it from the reader. Parameters
26+ * are read by value, as a terminal reads them: 08 and 8:1 are 8 too. The 8 in an extended color (38;5;8,
27+ * 48;2;8;8;8, 038;05;8) is a color, so those are copied whole. Nothing is left when 8 was all it said.
31+ const value = (p: string | undefined) => (p === undefined ? Number.NaN : Number(p.split(":")[0]));
46+
47+/** Whether a character code is one the terminal acts on: C0 but tab and newline, DEL, and C1. */
48+const control = (c: number) => (c < 0x20 && c !== 0x09 && c !== 0x0a) || (c >= 0x7f && c <= 0x9f);
49+
50+/** `text` as it is safe to print: colors kept only when `colors`, every other control character shown as text. */
67+ else out += c < 0x80 ? `\\x${c.toString(16).padStart(2, "0")}` : `\\u${c.toString(16).padStart(4, "0")}`;
- MCP
- compare on this site's /mcp
- CLI
- abso diff 2 318 client/src/terminal-text.ts --json
- JSON
- /christopher/abso-core/compare/2..318?file=client%2Fsrc%2Fterminal-text.ts&format=json