import { assert, assertEquals } from "@std/assert"; import { COLORS, contrast, readable } from "./palette.ts"; const [black, red, , yellow] = COLORS.palette; Deno.test("text that would not read on its background moves just far enough that it does", () => { // black on the terminal's own background, as a prompt's dimmest segment might be, becomes a dark gray const gray = readable(black, COLORS.background); assertEquals(gray[0], gray[1]); assertEquals(gray[1], gray[2]); assert(gray[0] < 128, `${gray} is dark`); // the default foreground on a bright background, as a status bar's might be, darkens const darker = readable(COLORS.foreground, yellow); assert(darker.every((c, i) => c < COLORS.foreground[i]), `${darker} is darker`); for (const [color, background] of [[gray, COLORS.background], [darker, yellow]]) { const ratio = contrast(color, background); assert(ratio >= 3 && ratio < 3.2, `${color} on ${background} reads, and only just: ${ratio}`); } // and anything that reads already stays as it is assertEquals(readable(red, COLORS.background), red); assertEquals(readable(black, yellow), black); });