Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion styles/gitbash/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $Host.UI.RawUI.WindowTitle = 'GITBASH // MINGW64'
function global:prompt {
$Esc = [char]27
$Green = "$Esc[38;2;0;128;0m"
$Yellow = "$Esc[38;2;166;160;0m"
$Yellow = "$Esc[38;2;155;150;29m"
$Cyan = "$Esc[38;2;0;119;119m"
$Magenta = "$Esc[38;2;187;0;187m"
$Gray = "$Esc[38;2;56;56;56m"
Expand Down
4 changes: 2 additions & 2 deletions styles/gitbash/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"black": "#000000",
"red": "#a31515",
"green": "#008000",
"yellow": "#a6a000",
"yellow": "#9b961d",
"blue": "#0000bb",
"purple": "#bb00bb",
"cyan": "#007777",
"white": "#bbbbbb",
"brightBlack": "#555555",
"brightRed": "#cd3131",
"brightGreen": "#11a52b",
"brightYellow": "#c4a500",
"brightYellow": "#ad9000",
"brightBlue": "#005ec1",
"brightPurple": "#bc05bc",
"brightCyan": "#00a3a3",
Expand Down
2 changes: 1 addition & 1 deletion styles/golden-forest/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"red": "#a85a2a",
"green": "#7a8f3e",
"yellow": "#d4a017",
"blue": "#4d5d3a",
"blue": "#566743",
"purple": "#8b6f3a",
"cyan": "#a9b87c",
"white": "#e8d68a",
Expand Down
2 changes: 1 addition & 1 deletion styles/neon-rain/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"green": "#5ee090",
"yellow": "#ffd848",
"blue": "#5a90d0",
"purple": "#5a4870",
"purple": "#6c6279",
"cyan": "#88c0e0",
"white": "#e8e8e0",
"brightBlack": "#2a3548",
Expand Down
2 changes: 1 addition & 1 deletion styles/rain/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (Get-Module -ListAvailable PSReadLine) {
Keyword = '#9CA0CC'
Member = '#C8C5DC'
Default = '#C8C5DC'
Error = '#A85850'
Error = '#A26D66'
Selection = "$Esc[48;2;60;64;96m"
}
try {
Expand Down
2 changes: 1 addition & 1 deletion styles/rain/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cursorColor": "#9ca0cc",
"selectionBackground": "#3c4060",
"black": "#0f1220",
"red": "#a85850",
"red": "#a26d66",
"green": "#5c8e5c",
"yellow": "#a89860",
"blue": "#7a8ac8",
Expand Down
2 changes: 1 addition & 1 deletion styles/snowday/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (Get-Module -ListAvailable PSReadLine) {
Operator = '#E8D4B8'
Variable = '#88A8B8'
Type = '#A08098'
Keyword = '#3A6890'
Keyword = '#44739B'
Member = '#E8D4B8'
Default = '#E8D4B8'
Error = '#C46850'
Expand Down
2 changes: 1 addition & 1 deletion styles/snowday/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"red": "#c46850",
"green": "#7a9078",
"yellow": "#d8b878",
"blue": "#3a6890",
"blue": "#44739b",
"purple": "#a08098",
"cyan": "#88a8b8",
"white": "#e8d4b8",
Expand Down
2 changes: 1 addition & 1 deletion styles/umbrella/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"green": "#6e8e6e",
"yellow": "#c9a66b",
"blue": "#7b6e5a",
"purple": "#8b3030",
"purple": "#815350",
"cyan": "#a89878",
"white": "#e8dcc8",
"brightBlack": "#4a423a",
Expand Down
58 changes: 58 additions & 0 deletions tests/Scheme-Contrast.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Legibility guard: every chromatic ANSI color in a bundled scheme.json must
# stay readable against that scheme's own background. Colored text below ~3:1
# reads as muddy syntax highlighting in the prompt. WCAG 1.4.11 puts the floor
# for non-body / accent color at 3:1, which is the right bar for terminal token
# colors (they are short identifiers, not paragraphs).
#
# Scope note: black / white (and their bright variants) are deliberately NOT
# checked -- they are the achromatic ends that blend into the background by
# design (e.g. gitbash is a light theme where white text is never used).
#
# Documented exceptions live in $allow below.
# Run: Invoke-Pester -Path tests
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0.0' }

Describe 'Bundled scheme color contrast' {
BeforeDiscovery {
$repoRoot = Split-Path $PSScriptRoot -Parent
$chromatic = 'red','green','yellow','blue','purple','cyan',
'brightRed','brightGreen','brightYellow','brightBlue','brightPurple','brightCyan'

# (theme/key) pairs intentionally allowed below the 3:1 floor.
# umbrella/red -- the theme's signature "blood red" (#b41e1e), used for
# the banner, prompt scaffolding and cursor. It sits at 2.99:1, within
# rounding of the floor; lifting it would shift the whole theme's
# identity for an imperceptible contrast gain.
$allow = @{ 'umbrella/red' = $true }

$cases = foreach ($dir in Get-ChildItem -LiteralPath (Join-Path $repoRoot 'styles') -Directory) {
$schemePath = Join-Path $dir.FullName 'scheme.json'
if (-not (Test-Path -LiteralPath $schemePath)) { continue }
$scheme = Get-Content -LiteralPath $schemePath -Raw | ConvertFrom-Json
foreach ($key in $chromatic) {
if (-not $scheme.$key) { continue }
if ($allow.ContainsKey("$($dir.Name)/$key")) { continue }
@{ Theme = $dir.Name; Key = $key; Color = [string]$scheme.$key; Background = [string]$scheme.background }
}
}
}

It '<Theme>/<Key> (<Color>) is >=3:1 against <Background>' -ForEach $cases {
function Get-RelativeLuminance([string]$hex) {
$h = $hex.TrimStart('#')
$chan = 0, 2, 4 | ForEach-Object {
$v = [Convert]::ToInt32($h.Substring($_, 2), 16) / 255
if ($v -le 0.03928) { $v / 12.92 } else { [math]::Pow(($v + 0.055) / 1.055, 2.4) }
}
0.2126 * $chan[0] + 0.7152 * $chan[1] + 0.0722 * $chan[2]
}

$lColor = Get-RelativeLuminance $Color
$lBg = Get-RelativeLuminance $Background
$hi = [math]::Max($lColor, $lBg)
$lo = [math]::Min($lColor, $lBg)
$ratio = ($hi + 0.05) / ($lo + 0.05)

$ratio | Should -BeGreaterThan 3.0 -Because "$Theme/$Key ($Color) must stay readable on $Background"
}
}
Loading