From 464c56862f9a23f0cfb58b59b8b77e9bd4e1c8a3 Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Fri, 10 Oct 2025 13:58:58 +0300 Subject: [PATCH] viz: update ansi regex (#12605) * viz: update ansi regex * better * add ansi_colors_light * javascript --- tinygrad/viz/js/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index c0b461b560..11b491e4a9 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -14,8 +14,9 @@ const darkenHex = (h, p = 0) => ).toString(16).padStart(6, '0')}`; const ANSI_COLORS = ["#b3b3b3", "#ff6666", "#66b366", "#ffff66", "#6666ff", "#ff66ff", "#66ffff", "#ffffff"]; +const ANSI_COLORS_LIGHT = ["#d9d9d9","#ff9999","#99cc99","#ffff99","#9999ff","#ff99ff","#ccffff","#ffffff"]; const parseColors = (name, defaultColor="#ffffff") => Array.from(name.matchAll(/(?:\u001b\[(\d+)m([\s\S]*?)\u001b\[0m)|([^\u001b]+)/g), - ([_, code, colored_st, st]) => ({ st: colored_st ?? st, color: code != null ? ANSI_COLORS[(parseInt(code)-30+60)%60] : defaultColor })); + ([_, code, colored_st, st]) => ({ st: colored_st ?? st, color: code != null ? (code>=90 ? ANSI_COLORS_LIGHT : ANSI_COLORS)[(parseInt(code)-30+60)%60] : defaultColor })); const rect = (s) => (typeof s === "string" ? document.querySelector(s) : s).getBoundingClientRect();