Skip to content

Commit

Permalink
test(status): Only reset changed colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Apr 19, 2019
1 parent 4cb398f commit 46296b7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@ function Write-Prompt {
[System.Collections.Generic.List[string]]$reset = @()
$e = [char]27 + "["

$bg = $bgColor
if (($null -ne $bg) -and !(Test-VirtualTerminalSequece $bg)) {
$bg = Get-BackgroundVirtualTerminalSequence $bg
$reset.Add('49')
}

$fg = $fgColor
if (($null -ne $fg) -and !(Test-VirtualTerminalSequece $fg)) {
$fg = Get-ForegroundVirtualTerminalSequence $fg
$reset.Add('39')
}

$bg = $bgColor
if (($null -ne $bg) -and !(Test-VirtualTerminalSequece $bg)) {
$bg = Get-BackgroundVirtualTerminalSequence $bg
$reset.Add('49')
}

$str = "${Object}"
if (Test-VirtualTerminalSequece $str -Force) {
$reset = @('0')
Expand Down
12 changes: 6 additions & 6 deletions src/PoshGitTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ class PoshGitTextSpan {
[System.Collections.Generic.List[string]]$reset = @()
$e = [char]27 + "["

$bg = $this.BackgroundColor
if (($null -ne $bg) -and !(Test-VirtualTerminalSequece $bg)) {
$bg = Get-BackgroundVirtualTerminalSequence $bg
$reset.Add('49')
}

$fg = $this.ForegroundColor
if (($null -ne $fg) -and !(Test-VirtualTerminalSequece $fg)) {
$fg = Get-ForegroundVirtualTerminalSequence $fg
$reset.Add('39')
}

$bg = $this.BackgroundColor
if (($null -ne $bg) -and !(Test-VirtualTerminalSequece $bg)) {
$bg = Get-BackgroundVirtualTerminalSequence $bg
$reset.Add('49')
}

$txt = $this.Text
$str = "${fg}${bg}${txt}"

Expand Down
4 changes: 2 additions & 2 deletions test/Ansi.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Describe 'ANSI Tests' {
It 'Setting BackgroundColor to 0x0 results in Black background' {
$ts = & $module.NewBoundScriptBlock({[PoshGitTextSpan]::new("TEST", 0xFF0000, 0)})
$ansiStr = $ts.toAnsiString()
$ansiStr | Should BeExactly "${csi}38;2;255;0;0m${csi}48;2;0;0;0mTEST${csi}0m"
$ansiStr | Should BeExactly "${csi}38;2;255;0;0m${csi}48;2;0;0;0mTEST${csi}39;49m"
}
It 'Setting ForegroundColor to 0x0 results in Black foreground' {
$ts = & $module.NewBoundScriptBlock({[PoshGitTextSpan]::new("TEST", 0, 0xFFFFFF)})
$ansiStr = $ts.toAnsiString()
$ansiStr | Should BeExactly "${csi}38;2;0;0;0m${csi}48;2;255;255;255mTEST${csi}0m"
$ansiStr | Should BeExactly "${csi}38;2;0;0;0m${csi}48;2;255;255;255mTEST${csi}39;49m"
}
}
}
20 changes: 10 additions & 10 deletions test/DefaultPrompt.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,37 @@ Describe 'Default Prompt Tests - ANSI' {
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::DarkBlue
$GitPromptSettings.DefaultPromptSuffix.BackgroundColor = 0xFF6000 # Orange
$res = &$prompt
$res | Should BeExactly "$(Get-PromptConnectionInfo)$(GetHomePath)${csi}34m${csi}48;2;255;96;0m`n> ${csi}0m"
$res | Should BeExactly "$(Get-PromptConnectionInfo)$(GetHomePath)${csi}34m${csi}48;2;255;96;0m`n> ${csi}39;49m"
}
It 'Returns the expected prompt string with expanded DefaultPromptSuffix' {
Set-Location $Home -ErrorAction Stop
$GitPromptSettings.DefaultPromptSuffix.Text = ' - $(6*7)> '
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::DarkBlue
$GitPromptSettings.DefaultPromptSuffix.BackgroundColor = 0xFF6000 # Orange
$res = &$prompt
$res | Should BeExactly "$(Get-PromptConnectionInfo)$(GetHomePath)${csi}34m${csi}48;2;255;96;0m - 42> ${csi}0m"
$res | Should BeExactly "$(Get-PromptConnectionInfo)$(GetHomePath)${csi}34m${csi}48;2;255;96;0m - 42> ${csi}39;49m"
}
It 'Returns the expected prompt string with changed DefaultPromptPrefix' {
Set-Location $Home -ErrorAction Stop
$GitPromptSettings.DefaultPromptPrefix.Text = 'PS '
$GitPromptSettings.DefaultPromptPrefix.BackgroundColor = [ConsoleColor]::White
$res = &$prompt
$res | Should BeExactly "${csi}107mPS ${csi}0m$(GetHomePath)> "
$res | Should BeExactly "${csi}107mPS ${csi}49m$(GetHomePath)> "
}
It 'Returns the expected prompt string with expanded DefaultPromptPrefix' {
Set-Location $Home -ErrorAction Stop
$GitPromptSettings.DefaultPromptPrefix.Text = '[$(hostname)] '
$GitPromptSettings.DefaultPromptPrefix.BackgroundColor = 0xF5F5F5
$res = &$prompt
$res | Should BeExactly "${csi}48;2;245;245;245m[$(hostname)] ${csi}0m$(GetHomePath)> "
$res | Should BeExactly "${csi}48;2;245;245;245m[$(hostname)] ${csi}49m$(GetHomePath)> "
}
It 'Returns the expected prompt path colors' {
Set-Location $Home -ErrorAction Stop
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
$GitPromptSettings.DefaultPromptPath.ForegroundColor = [ConsoleColor]::DarkCyan
$GitPromptSettings.DefaultPromptPath.BackgroundColor = [ConsoleColor]::DarkRed
$res = &$prompt
$res | Should BeExactly "$(Get-PromptConnectionInfo)${csi}36m${csi}41m$(GetHomePath)${csi}0m> "
$res | Should BeExactly "$(Get-PromptConnectionInfo)${csi}36m${csi}41m$(GetHomePath)${csi}39;49m> "
}
It 'Returns the expected prompt string with prefix, suffix and abbrev home set' {
Set-Location $Home -ErrorAction Stop
Expand All @@ -202,7 +202,7 @@ Describe 'Default Prompt Tests - ANSI' {
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::DarkBlue
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
$res = &$prompt
$res | Should BeExactly "${csi}38;2;245;245;245m[$(hostname)] ${csi}0m$(GetHomePath)${csi}34m - 42> ${csi}0m"
$res | Should BeExactly "${csi}38;2;245;245;245m[$(hostname)] ${csi}39m$(GetHomePath)${csi}34m - 42> ${csi}39m"
}
It 'Returns the expected prompt string with prompt timing enabled' {
Set-Location $Home -ErrorAction Stop
Expand All @@ -211,7 +211,7 @@ Describe 'Default Prompt Tests - ANSI' {
$res = &$prompt
$escapedHome = [regex]::Escape((GetHomePath))
$rexcsi = [regex]::Escape($csi)
$res | Should Match "$escapedHome${rexcsi}95m \d+ms${rexcsi}0m> "
$res | Should Match "$escapedHome${rexcsi}95m \d+ms${rexcsi}39m> "
}
}

Expand All @@ -238,7 +238,7 @@ A test/Foo.Tests.ps1
$res = &$prompt
Assert-MockCalled git -ModuleName posh-git
$path = GetHomeRelPath $PSScriptRoot
$res | Should BeExactly "$(Get-PromptConnectionInfo)$path ${csi}93m[${csi}0m${csi}96mmaster${csi}0m${csi}32m${csi}49m +1${csi}0m${csi}32m${csi}49m ~0${csi}0m${csi}32m${csi}49m -0${csi}0m${csi}93m |${csi}0m${csi}31m${csi}49m +0${csi}0m${csi}31m${csi}49m ~1${csi}0m${csi}31m${csi}49m -1${csi}0m${csi}31m !${csi}0m${csi}93m]${csi}0m> "
$res | Should BeExactly "$(Get-PromptConnectionInfo)$path ${csi}93m[${csi}39m${csi}96mmaster${csi}39m${csi}32m +1${csi}39m${csi}32m ~0${csi}39m${csi}32m -0${csi}39m${csi}93m |${csi}39m${csi}31m +0${csi}39m${csi}31m ~1${csi}39m${csi}31m -1${csi}39m${csi}31m !${csi}39m${csi}93m]${csi}39m> "
}

It 'Returns the expected prompt string with changed PathStatusSeparator' {
Expand All @@ -258,7 +258,7 @@ A test/Foo.Tests.ps1
$res = [string](&$prompt *>&1)
Assert-MockCalled git -ModuleName posh-git -Scope It
$path = GetHomeRelPath $PSScriptRoot
$res | Should BeExactly "$(Get-PromptConnectionInfo)$path${csi}107m !! ${csi}0m${csi}93m[${csi}0m${csi}96mmaster${csi}0m${csi}93m]${csi}0m> "
$res | Should BeExactly "$(Get-PromptConnectionInfo)$path${csi}107m !! ${csi}49m${csi}93m[${csi}39m${csi}96mmaster${csi}39m${csi}93m]${csi}39m> "
}
It 'Returns the expected prompt string with expanded PathStatusSeparator' {
Mock -ModuleName posh-git -CommandName git {
Expand All @@ -277,7 +277,7 @@ A test/Foo.Tests.ps1
$res = [string](&$prompt *>&1)
Assert-MockCalled git -ModuleName posh-git -Scope It
$path = GetHomeRelPath $PSScriptRoot
$res | Should BeExactly "$(Get-PromptConnectionInfo)$path${csi}107m [$(hostname)] ${csi}0m${csi}93m[${csi}0m${csi}96mmaster${csi}0m${csi}93m]${csi}0m> "
$res | Should BeExactly "$(Get-PromptConnectionInfo)$path${csi}107m [$(hostname)] ${csi}49m${csi}93m[${csi}39m${csi}96mmaster${csi}39m${csi}93m]${csi}39m> "
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/GitPrompt.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ M test/Baz.Tests.ps1

It 'Returns status output from Write-VcsStatus as string' {
$res = Write-VcsStatus
$res | Should BeExactly " ${csi}93m[${csi}0m${csi}96mmaster${csi}0m${csi}32m${csi}49m +1${csi}0m${csi}32m${csi}49m ~0${csi}0m${csi}32m${csi}49m -0${csi}0m${csi}96m ~${csi}0m${csi}93m]${csi}0m"
$res | Should BeExactly " ${csi}93m[${csi}39m${csi}96mmaster${csi}39m${csi}32m +1${csi}39m${csi}32m ~0${csi}39m${csi}32m -0${csi}39m${csi}96m ~${csi}39m${csi}93m]${csi}39m"
}
}
}

0 comments on commit 46296b7

Please sign in to comment.