From 5217231f6e7c8097e3d2d2e8ddf2552003cd80d5 Mon Sep 17 00:00:00 2001 From: Anthony Rose Date: Thu, 13 Feb 2025 09:58:56 +0000 Subject: [PATCH] Use Microsoft-recommended light mode --- .../files/Microsoft.PowerShell_profile.ps1 | 80 +++++++++++-------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 index 41bf0a1..513534d 100644 --- a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 +++ b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 @@ -118,41 +118,55 @@ foreach ($Property in $Host.PrivateData.PSObject.Properties.Name) { } } -[bool]$LightMode = $true -if ($LightMode) { - $Host.PrivateData.ErrorForegroundColor = [ConsoleColor]::DarkRed - $Host.PrivateData.ErrorBackgroundColor = [ConsoleColor]::White - $Host.PrivateData.WarningForegroundColor = [ConsoleColor]::DarkYellow - $Host.PrivateData.WarningBackgroundColor = [ConsoleColor]::White - $Host.PrivateData.DebugForegroundColor = [ConsoleColor]::DarkYellow - $Host.PrivateData.DebugBackgroundColor = [ConsoleColor]::White - $Host.PrivateData.VerboseForegroundColor = [ConsoleColor]::DarkYellow - $Host.PrivateData.VerboseBackgroundColor = [ConsoleColor]::White - $Host.PrivateData.ProgressForegroundColor = [ConsoleColor]::DarkYellow - $Host.PrivateData.ProgressBackgroundColor = [ConsoleColor]::White - $PSReadLineLightColors = @{ - Default = "$([char]0x1b)[0m" - Command = "$([char]0x1b)[0m" - Comment = "$([char]0x1b)[32m" - ContinuationPrompt = "$([char]0x1b)[0m" - Emphasis = "$([char]0x1b)[36m" - Error = "$([char]0x1b)[91m" - InlinePrediction = "$([char]0x1b)[95m" - Keyword = "$([char]0x1b)[32m" - ListPrediction = "$([char]0x1b)[47;90m" - ListPredictionSelected = "$([char]0x1b)[100;97m" - ListPredictionTooltip = "$([char]0x1b)[45;33m" - Member = "$([char]0x1b)[0m" - Number = "$([char]0x1b)[31m" - Operator = "$([char]0x1b)[90m" - Parameter = "$([char]0x1b)[90m" - Selection = "$([char]0x1b)[7m" - String = "$([char]0x1b)[36m" - Type = "$([char]0x1b)[0m" - Variable = "$([char]0x1b)[32m" +function Set-AntLightMode { + # https://learn.microsoft.com/en-us/powershell/scripting/learn/shell/using-light-theme + + if ($PSVersionTable.PSVersion.Major -le 5) { + # $PSStyle doesn't exist in PowerShell 5.1, so import the external module. + Import-Module -Name PSStyle } - Set-PSReadLineOption -Colors $PSReadLineLightColors + + $ISETheme = @{ + Command = $PSStyle.Foreground.FromRGB(0x0000FF) + Comment = $PSStyle.Foreground.FromRGB(0x006400) + ContinuationPrompt = $PSStyle.Foreground.FromRGB(0x0000FF) + Default = $PSStyle.Foreground.FromRGB(0x0000FF) + Emphasis = $PSStyle.Foreground.FromRGB(0x287BF0) + Error = $PSStyle.Foreground.FromRGB(0xE50000) + InlinePrediction = $PSStyle.Foreground.FromRGB(0x93A1A1) + Keyword = $PSStyle.Foreground.FromRGB(0x00008b) + ListPrediction = $PSStyle.Foreground.FromRGB(0x06DE00) + Member = $PSStyle.Foreground.FromRGB(0x000000) + Number = $PSStyle.Foreground.FromRGB(0x800080) + Operator = $PSStyle.Foreground.FromRGB(0x757575) + Parameter = $PSStyle.Foreground.FromRGB(0x000080) + String = $PSStyle.Foreground.FromRGB(0x8b0000) + Type = $PSStyle.Foreground.FromRGB(0x008080) + Variable = $PSStyle.Foreground.FromRGB(0xff4500) + ListPredictionSelected = $PSStyle.Background.FromRGB(0x93A1A1) + Selection = $PSStyle.Background.FromRGB(0x00BFFF) + } + $PSStyle.Formatting.FormatAccent = "`e[32m" + $PSStyle.Formatting.TableHeader = "`e[32m" + $PSStyle.Formatting.ErrorAccent = "`e[36m" + $PSStyle.Formatting.Error = "`e[31m" + $PSStyle.Formatting.Warning = "`e[33m" + $PSStyle.Formatting.Verbose = "`e[33m" + $PSStyle.Formatting.Debug = "`e[33m" + $PSStyle.Progress.Style = "`e[33m" + $PSStyle.FileInfo.Directory = $PSStyle.Background.FromRgb(0x2f6aff) + + $PSStyle.Foreground.BrightWhite + $PSStyle.FileInfo.SymbolicLink = "`e[36m" + $PSStyle.FileInfo.Executable = "`e[95m" + if ($PSVersionTable.PSVersion.Major -gt 5) { + $PSStyle.FileInfo.Extension['.ps1'] = "`e[36m" + $PSStyle.FileInfo.Extension['.ps1xml'] = "`e[36m" + $PSStyle.FileInfo.Extension['.psd1'] = "`e[36m" + $PSStyle.FileInfo.Extension['.psm1'] = "`e[36m" + } + Set-PSReadLineOption -Colors $ISETheme } +Set-AntLightMode # Keep this at the end. if (Test-Path "$PSScriptRoot/local.ps1") {