1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00
This commit is contained in:
Nicolò Ribaudo 2025-01-20 16:23:32 +01:00 committed by GitHub
commit b8cfb98d45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2842,15 +2842,20 @@ function parseCss(cssString) {
return css; return css;
} }
function colorEquals(color1, color2) { // The same color can be represented in multiple formats. This function
return color1?.[0] == color2?.[0] && color1?.[1] == color2?.[1] && // returns `false` in that case.
color1?.[2] == color2?.[2]; function colorsObviouslyEqual(color1, color2) {
if (ArrayIsArray(color1) && ArrayIsArray(color2)) {
return color1[0] === color2[0] && color1[1] === color2[1] &&
color1[2] === color2[2];
}
return color1 === color2;
} }
function cssToAnsi(css, prevCss = null) { function cssToAnsi(css, prevCss = null) {
prevCss = prevCss ?? getDefaultCss(); prevCss = prevCss ?? getDefaultCss();
let ansi = ""; let ansi = "";
if (!colorEquals(css.backgroundColor, prevCss.backgroundColor)) { if (!colorsObviouslyEqual(css.backgroundColor, prevCss.backgroundColor)) {
if (css.backgroundColor == null) { if (css.backgroundColor == null) {
ansi += "\x1b[49m"; ansi += "\x1b[49m";
} else if (css.backgroundColor == "black") { } else if (css.backgroundColor == "black") {
@ -2884,7 +2889,7 @@ function cssToAnsi(css, prevCss = null) {
} }
} }
} }
if (!colorEquals(css.color, prevCss.color)) { if (!colorsObviouslyEqual(css.color, prevCss.color)) {
if (css.color == null) { if (css.color == null) {
ansi += "\x1b[39m"; ansi += "\x1b[39m";
} else if (css.color == "black") { } else if (css.color == "black") {
@ -2932,7 +2937,9 @@ function cssToAnsi(css, prevCss = null) {
ansi += "\x1b[23m"; ansi += "\x1b[23m";
} }
} }
if (!colorEquals(css.textDecorationColor, prevCss.textDecorationColor)) { if (
!colorsObviouslyEqual(css.textDecorationColor, prevCss.textDecorationColor)
) {
if (css.textDecorationColor != null) { if (css.textDecorationColor != null) {
const { 0: r, 1: g, 2: b } = css.textDecorationColor; const { 0: r, 1: g, 2: b } = css.textDecorationColor;
ansi += `\x1b[58;2;${r};${g};${b}m`; ansi += `\x1b[58;2;${r};${g};${b}m`;