Fixes two bugs - one ANSI and one PS Core#532
Conversation
The ANSI bug is that if both fg and bg are default ($null) we were still emitting the terminating seq `e[0m. The PS Core bug is that on PS Core there is no byte value for Get-Content -Encoding. The replacement is Get-Content -AsByteStream.
dahlbyk
left a comment
There was a problem hiding this comment.
Fixes look good, but it seems like we could simplify the ANSI code?
src/PoshGitTypes.ps1
Outdated
| $this.CustomAnsi = $null | ||
| } | ||
|
|
||
| [string] ToEscapedString() { |
There was a problem hiding this comment.
Isn't this whole method equivalent to EscapeAnsiString $this.RenderAnsi()?
| return $str | ||
| } | ||
|
|
||
| [string] ToEscapedString() { |
There was a problem hiding this comment.
Does it make sense for PoshGitCellColor to have a RenderAnsi(), such that this function is essentially EscapeAnsiString $this.RenderAnsi()? That function could then be used in PoshGitTextSpan.
There was a problem hiding this comment.
Also, would ToAnsiString() be a better name than RenderAnsi()?
There was a problem hiding this comment.
That's what I get for coding and watching the playoffs. :-) Renamed RenderAnsi() to ToAnsiString(). Can we do the [PoshGitCellColor] tweaks - ToAnsiString() and ToEscapedString() simplification in another PR?
There was a problem hiding this comment.
Yeah, that works. While you're at it, fix the typo in EscapseAnsiString. 😏
There was a problem hiding this comment.
Doh! Yeah, will do.
| } | ||
|
|
||
| [string] ToEscapedString() { | ||
| if ($global:GitPromptSettings.AnsiConsole) { |
There was a problem hiding this comment.
Not a blocker, but should ToEscapedString() care if the console supports ANSI? Properly encoding/escaping a string doesn't require it…
The ANSI bug is that if both fg and bg are default ($null) we were still emitting the terminating seq `e[0m.
The PS Core bug is that on PS Core there is no byte value for Get-Content -Encoding. The replacement is Get-Content -AsByteStream.
Also. added ToEscapedString() method to [PoshGitCellColor] and [PoshGitTextSpan]. Was invaluable for working on the Pester tests and I think it will be very handy for debugging. If someone's GitPrompSettings isn't displaying properly we can ask them to execute:
$GitPromptSettings.DelimText.ToEscapedString()This will output:
`e[93m |`e[0m