MCPcopy Create free account
hub / github.com/modem-dev/hunk / themeModeForBackgroundColor

Function themeModeForBackgroundColor

src/core/themeDetection.ts:68–75  ·  view source on GitHub ↗
({ red, green, blue }: RgbColor)

Source from the content-addressed store, hash-verified

66
67/** Classify a background color using relative luminance. */
68export function themeModeForBackgroundColor({ red, green, blue }: RgbColor): TerminalThemeMode {
69 const linear = [red, green, blue].map((component) => {
70 const normalized = component / 255;
71 return normalized <= 0.03928 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
72 });
73 const luminance = 0.2126 * linear[0]! + 0.7152 * linear[1]! + 0.0722 * linear[2]!;
74 return luminance > 0.5 ? "light" : "dark";
75}
76
77/**
78 * Probe the terminal background via OSC 11 using the same input stream OpenTUI uses for mouse.

Callers 3

onDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected