({ red, green, blue }: RgbColor)
| 66 | |
| 67 | /** Classify a background color using relative luminance. */ |
| 68 | export 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. |
no outgoing calls
no test coverage detected