Skip to content
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

Refactor Settings & Write-GitStatus function #513

Merged
merged 24 commits into from
Jan 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a7b01c5
WIP: A simpler take at organizing settings using v5 classes
rkeithhill Oct 29, 2017
7460daf
Reorder some settings
rkeithhill Oct 29, 2017
98c61bb
Make sure value is not null
rkeithhill Oct 29, 2017
b28513c
Try another approach with custom ansi
rkeithhill Oct 29, 2017
4d8e08c
WIP - refactor Write-Prompt
rkeithhill Oct 29, 2017
8fcfc21
WIP refactor Write-GitStatus into individual Write-* methods.
rkeithhill Oct 30, 2017
7fb0d6d
Prefix new function nouns with "Git"
rkeithhill Oct 30, 2017
8dee3e7
Rename GitWorkingDirectory to GitWorkingDir
rkeithhill Oct 30, 2017
71a085a
Favor ConsoleColor over HtmlColor
rkeithhill Nov 28, 2017
fa2b05b
Change var name from $res to $prompt
rkeithhill Nov 28, 2017
facc87d
Convert from untyped settings to strongly typed settings
rkeithhill Dec 29, 2017
5120624
Add Write-GitBranchName
rkeithhill Jan 1, 2018
88312b2
Fix a typo in help comment
rkeithhill Jan 1, 2018
b656d1e
Prep branch for a possible publish as Beta1
rkeithhill Jan 1, 2018
db734a6
Export $GitPromptScriptBlock variable
rkeithhill Jan 1, 2018
b7b58bc
Merge from develop
rkeithhill Jan 1, 2018
53cb658
Fix Write-VcsStatus issue with returning array of prompt strings
rkeithhill Jan 2, 2018
a3a4ffe
Address PR feedback on -Status param help
rkeithhill Jan 2, 2018
2af60e0
Address PR feedback to move types to separate file
rkeithhill Jan 2, 2018
6235734
Adjust Prerelease field - set to `alpha`
rkeithhill Jan 2, 2018
9f9a649
Address PR feedback - simplify Write-VcsStatus
rkeithhill Jan 2, 2018
635c113
Address PR feedback - DarkCyan back to Cyan
rkeithhill Jan 2, 2018
041c286
Fix bug where color 'Black' wasn't matching ConsoleColor
rkeithhill Jan 3, 2018
2831c0c
Add -Color parameter to Write-Prompt
rkeithhill Jan 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,19 @@ if (!(Test-Path Variable:Global:VcsPromptStatuses)) {
#>
function Global:Write-VcsStatus {
Set-ConsoleMode -ANSI
$global:VcsPromptStatuses | ForEach-Object { & $_ }
$OFS = ""
$sb = [System.Text.StringBuilder]::new(200)

$global:VcsPromptStatuses | ForEach-Object {
$str = & $_
if ($str) {
# $str is quoted in case we get back an array of strings, quoting it will flatten the array
# into a single string and $OFS="" will ensure no spaces between each array item.
$sb.Append("$str") > $null
}
}

$sb.ToString()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be oversimplifying, but isn't this the same as:

$OFS = ""
"$($global:VcsPromptStatuses | ForEach-Object { & $_ })"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. I was following the pattern we'd established in Write-Git*Status methods. Just thinking of the case where AnsiConsole is disabled - that should write to the host and not return anything (or empty strings) and those should concat to an empty string. So yeah, that should work. Want me to change this (and test it)?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm all for less code. 99.99+% of the time there's a single status function with a single result.

}

# Add scriptblock that will execute for Write-VcsStatus
Expand All @@ -1064,9 +1076,16 @@ $PoshGitVcsPrompt = {
catch {
$s = $global:GitPromptSettings
if ($s) {
Write-Prompt $s.BeforeText
Write-Prompt "Error: $_" -BackgroundColor $s.ErrorColor.BackgroundColor -ForegroundColor $s.ErrorColor.ForegroundColor
Write-Prompt $s.AfterText
$errorTextSpan = [PoshGitTextSpan]::new($s.ErrorColor)
$errorTextSpan.Text = "PoshGitVcsPrompt error: $_"

$sb = [System.Text.StringBuilder]::new()

$sb | Write-Prompt $s.BeforeText > $null
$sb | Write-Prompt $errorTextSpan > $null
$sb | Write-Prompt $s.AfterText > $null

$sb.ToString()
}
}
}
Expand Down