Skip to content

Commit 303fbd0

Browse files
committed
Make Write-Prompt more forgiving
1 parent a6d0db7 commit 303fbd0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/GitPrompt.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,25 @@ if (Get-Module NuGet) {
127127
$WindowTitleSupported = $false
128128
}
129129

130-
function Write-Prompt($Object, $ForegroundColor, $BackgroundColor = -1) {
131-
if ($BackgroundColor -lt 0) {
132-
Write-Host $Object -NoNewLine -ForegroundColor $ForegroundColor
133-
} else {
134-
Write-Host $Object -NoNewLine -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor
130+
function Write-Prompt($Object, $ForegroundColor = $null, $BackgroundColor = $null) {
131+
if ($BackgroundColor -is [string]) {
132+
$BackgroundColor = [ConsoleColor]$BackgroundColor
135133
}
134+
if ($ForegroundColor -is [string]) {
135+
$ForegroundColor = [ConsoleColor]$ForegroundColor
136+
}
137+
138+
$writeHostParams = @{
139+
Object = $Object;
140+
NoNewLine = $true;
141+
}
142+
if (($BackgroundColor -ge 0) -and ($BackgroundColor -le 15)) {
143+
$writeHostParams.BackgroundColor = $BackgroundColor
144+
}
145+
if (($ForegroundColor -ge 0) -and ($ForegroundColor -le 15)) {
146+
$writeHostParams.ForegroundColor = $ForegroundColor
147+
}
148+
Write-Host @writeHostParams
136149
}
137150

138151
function Format-BranchName($branchName){

0 commit comments

Comments
 (0)