PWRSWriteColorEX.psm1

$root = $PSScriptRoot
$tfm = if ($PSVersionTable.PSEdition -eq 'Core') { 'net10.0' } else { 'netstandard2.0' }
if (-not ('Pwrs.Bootstrap.Loader' -as [type])) {
$stage = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'pwrs-load', [string]$PID, 'boot', '6dff60574f888d61', $tfm)
$null = [System.IO.Directory]::CreateDirectory($stage)
$boot = [System.IO.Path]::Combine($stage, 'Pwrs.Bootstrap.dll')
if (-not [System.IO.File]::Exists($boot)) {
$partial = $boot + '.' + [System.Guid]::NewGuid().ToString('N') + '.partial'
[System.IO.File]::Copy([System.IO.Path]::Combine($root, $tfm, 'Pwrs.Bootstrap.dll'), $partial)
try { [System.IO.File]::Move($partial, $boot) }
catch [System.IO.IOException] {
[System.IO.File]::Delete($partial)
if (-not [System.IO.File]::Exists($boot)) { throw }
}
}
$null = [System.Reflection.Assembly]::LoadFrom($boot)
}
try { $shell = [Pwrs.Bootstrap.Loader]::Load($root, 'PWRSWriteColorEX', $tfm) }
catch {
if ($tfm -eq 'net10.0' -and [Environment]::Version.Major -lt 8) {
throw ('PWRSWriteColorEX' + ' needs PowerShell 7.4 or later: its PowerShell 7 half is built against .NET 8, and this is PowerShell ' + $PSVersionTable.PSVersion + ' on .NET ' + [Environment]::Version + '.')
}
throw
}
$shell.GetType('Pwrs.Modules.PWRSWriteColorEX.PwrsModuleRoot', $true).GetField('Value').SetValue($null, $root)
if ($tfm -eq 'netstandard2.0') {
$staged = [System.IO.Path]::GetDirectoryName($shell.Location)
foreach ($dep in @('System.Numerics.Vectors.dll', 'System.Memory.dll', 'System.Buffers.dll', 'System.Runtime.CompilerServices.Unsafe.dll')) {
$to = [System.IO.Path]::Combine($staged, $dep)
if (-not [System.IO.File]::Exists($to)) {
$partial = $to + '.' + [System.Guid]::NewGuid().ToString('N') + '.partial'
[System.IO.File]::Copy([System.IO.Path]::Combine($root, $tfm, $dep), $partial)
try { [System.IO.File]::Move($partial, $to) }
catch [System.IO.IOException] {
[System.IO.File]::Delete($partial)
if (-not [System.IO.File]::Exists($to)) { throw }
}
}
}
}
foreach ($m in Get-Module -All) {
if ($m.ModuleType -eq 'Binary' -and ($m.Path -eq $shell.Location -or $m.Name -like '*PWRSWriteColorEX.Shell*')) {
Remove-Module -ModuleInfo $m -Force -ErrorAction SilentlyContinue
}
}
try {
Import-Module -Assembly $shell -Force
$reload = $shell.GetTypes() | Where-Object { $_.Name -eq 'PwrsModule' } | Select-Object -First 1
if ($null -ne $reload) { $null = $reload::ReloadNative() }
}
catch {
$inner = $_.Exception
while ($null -ne $inner.InnerException) { $inner = $inner.InnerException }
throw $inner
}
Export-ModuleMember -Cmdlet 'Write-ColorEX', 'Write-ColorError', 'Write-ColorWarning', 'Write-ColorInfo', 'Write-ColorSuccess', 'Write-ColorCritical', 'Write-ColorDebug', 'Set-ColorDefault', 'Get-ColorProfiles', 'New-ColorStyle', 'Test-AnsiSupport', 'Convert-HexToRGB', 'Convert-RGBToANSI8', 'Convert-RGBToANSI4', 'Get-ColorTableWithRGB', 'Measure-DisplayWidth', 'Get-LighterRGBColor', 'Get-LighterColorName', 'Get-LighterANSI8Color', 'Format-ColorEX', 'Show-ColorTable', 'Register-ColorName', 'Unregister-ColorName', 'Export-ColorProfile', 'Import-ColorProfile', 'Remove-ColorProfile' -Alias 'Write-ColourEX', 'Write-Color', 'Write-Colour', 'WC', 'WCEX', 'wcolor', 'wcolour', 'WCE', 'Write-ErrorColor', 'Write-ErrorColour', 'Write-ColourError', 'WError', 'wcerror', 'WCW', 'Write-WarningColor', 'Write-WarningColour', 'Write-ColourWarning', 'WWarning', 'WCWarn', 'wcwarning', 'WCI', 'Write-InfoColor', 'Write-InfoColour', 'Write-ColourInfo', 'WInfo', 'wcinfo', 'WCS', 'Write-SuccessColor', 'Write-SuccessColour', 'Write-ColourSuccess', 'WSuccess', 'wcok', 'wcsuccess', 'WCC', 'Write-CriticalColor', 'Write-CriticalColour', 'Write-ColourCritical', 'WCritical', 'wccritical', 'WCD', 'Write-DebugColor', 'Write-DebugColour', 'Write-ColourDebug', 'WDebug', 'wcdebug', 'SCD', 'Set-ColourDefault', 'Set-DefaultColor', 'Set-DefaultColour', 'GCP', 'Get-ColourProfiles', 'Get-Profiles', 'gcprofiles', 'NCS', 'New-ColourStyle', 'New-Style', 'ncstyle', 'TAS', 'Test-ANSI', 'CHR', 'Hex2RGB', 'CRA8', 'RGB2ANSI8', 'CRA4', 'RGB2ANSI4', 'GCT', 'Get-ColorTable', 'Get-ColourTable', 'MDW', 'Get-DisplayWidth', 'Lighten-RGBColor', 'Lighten-ColorName', 'LA8', 'Lighten-ANSI8', 'Lighten-ANSI8Color', 'Format-ColourEX', 'FCEX', 'Show-ColourTable', 'Register-ColourName', 'Unregister-ColourName', 'Export-ColourProfile', 'Import-ColourProfile', 'Remove-ColourProfile'