-
-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes two bugs - one ANSI and one PS Core #532
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ class PoshGitCellColor { | |
$this.BackgroundColor = $BackgroundColor | ||
} | ||
|
||
hidden [string] ToString($color) { | ||
hidden static [string] ToString($color) { | ||
$ansiTerm = "$([char]0x1b)[0m" | ||
$colorSwatch = " " | ||
|
||
|
@@ -44,11 +44,41 @@ class PoshGitCellColor { | |
return $str | ||
} | ||
|
||
[string] ToEscapedString() { | ||
if (!$global:GitPromptSettings.AnsiConsole) { | ||
return "" | ||
} | ||
|
||
$str = "" | ||
|
||
if ($this.ForegroundColor) { | ||
if (Test-VirtualTerminalSequece $this.ForegroundColor) { | ||
$str += EscapseAnsiString $this.ForegroundColor | ||
} | ||
else { | ||
$seq = Get-ForegroundVirtualTerminalSequence $this.ForegroundColor | ||
$str += EscapseAnsiString $seq | ||
} | ||
} | ||
|
||
if ($this.BackgroundColor) { | ||
if (Test-VirtualTerminalSequece $this.BackgroundColor) { | ||
$str += EscapseAnsiString $this.BackgroundColor | ||
} | ||
else { | ||
$seq = Get-BackgroundVirtualTerminalSequence $this.BackgroundColor | ||
$str += EscapseAnsiString $seq | ||
} | ||
} | ||
|
||
return $str | ||
} | ||
|
||
[string] ToString() { | ||
$str = "ForegroundColor: " | ||
$str += $this.ToString($this.ForegroundColor) + ", " | ||
$str += [PoshGitCellColor]::ToString($this.ForegroundColor) + ", " | ||
$str += "BackgroundColor: " | ||
$str += $this.ToString($this.BackgroundColor) | ||
$str += [PoshGitCellColor]::ToString($this.BackgroundColor) | ||
return $str | ||
} | ||
} | ||
|
@@ -101,6 +131,32 @@ class PoshGitTextSpan { | |
$this.CustomAnsi = $null | ||
} | ||
|
||
[string] ToEscapedString() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this whole method equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. Done. |
||
if ($global:GitPromptSettings.AnsiConsole) { | ||
$ansiTerm = EscapseAnsiString ([char]27 + "[0m") | ||
|
||
if ($this.CustomAnsi) { | ||
$escAnsi = EscapseAnsiString $this.CustomAnsi | ||
$str = "${escAnsi}$($this.Text)$ansiTerm" | ||
} | ||
else { | ||
$color = [PoshGitCellColor]::new($this.ForegroundColor, $this.BackgroundColor) | ||
$escAnsi = $color.ToEscapedString() | ||
if ($escAnsi) { | ||
$str = "${escAnsi}$($this.Text)$ansiTerm" | ||
} | ||
else { | ||
$str = $this.Text | ||
} | ||
} | ||
} | ||
else { | ||
$str = $this.Text | ||
} | ||
|
||
return $str | ||
} | ||
|
||
[string] ToString() { | ||
if ($global:GitPromptSettings.AnsiConsole) { | ||
if ($this.CustomAnsi) { | ||
|
@@ -144,7 +200,12 @@ class PoshGitTextSpan { | |
$fg = Get-ForegroundVirtualTerminalSequence $fg | ||
} | ||
|
||
$str = "${fg}${bg}${txt}${e}0m" | ||
if (($null -ne $fg) -or ($null -ne $bg)) { | ||
$str = "${fg}${bg}${txt}${e}0m" | ||
} | ||
else { | ||
$str = $txt | ||
} | ||
} | ||
|
||
return $str | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense for
PoshGitCellColor
to have aRenderAnsi()
, such that this function is essentiallyEscapeAnsiString $this.RenderAnsi()
? That function could then be used inPoshGitTextSpan
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would
ToAnsiString()
be a better name thanRenderAnsi()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I get for coding and watching the playoffs. :-) Renamed
RenderAnsi()
toToAnsiString()
. Can we do the[PoshGitCellColor]
tweaks - ToAnsiString() and ToEscapedString() simplification in another PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that works. While you're at it, fix the typo in
EscapseAnsiString
. 😏There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! Yeah, will do.