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

Replace or improve $GitPromptSettings #344

Closed
rkeithhill opened this issue Dec 31, 2016 · 16 comments
Closed

Replace or improve $GitPromptSettings #344

rkeithhill opened this issue Dec 31, 2016 · 16 comments

Comments

@rkeithhill
Copy link
Collaborator

It is really hard to find a setting in the output of $GitPrompSettings:

LocalWorkingStatusForegroundColor         : DarkRed
FileModifiedText                          : ~
AfterStashBackgroundColor                 : Black
WorkingForegroundBrightColor              : Red
RepositoriesInWhichToDisableFileStatus    : {}
IndexForegroundColor                      : DarkGreen
BranchForegroundColor                     : Cyan
BeforeStashForegroundColor                : Red
EnablePromptStatus                        : True
AfterBackgroundColor                      : Black
FileRemovedText                           : -
BeforeIndexBackgroundColor                : Black
AfterText                                 : ]
BeforeForegroundColor                     : Yellow
LocalWorkingStatusSymbol                  : !
BranchAheadStatusSymbol                   : ↑
LocalDefaultStatusSymbol                  :
IndexForegroundBrightColor                : Green
IndexBackgroundColor                      : Black
LocalStagedStatusForegroundColor          : Cyan
ShowStatusWhenZero                        : True
WorkingForegroundColor                    : DarkRed
BranchIdenticalStatusToBackgroundColor    : Black
BeforeIndexForegroundColor                : DarkGreen
BranchIdenticalStatusToSymbol             : ≡
BranchBehindAndAheadStatusForegroundColor : Yellow
LocalDefaultStatusForegroundColor         : DarkGreen
DescribeStyle                             :
BranchBackgroundColor                     : Black
LocalStagedStatusBackgroundColor          : Black
BranchIdenticalStatusToForegroundColor    : Cyan
AfterStashText                            : )
BeforeBackgroundColor                     : Black
BeforeIndexForegroundBrightColor          : Green
EnableStashStatus                         : False
Debug                                     : False
LocalWorkingStatusForegroundBrightColor   : Red
LocalWorkingStatusBackgroundColor         : Black
LocalStagedStatusSymbol                   : ~
DelimText                                 :  |
BranchBehindAndAheadStatusSymbol          : ↕
WorkingBackgroundColor                    : Black
BeforeStashBackgroundColor                : Black
DefaultForegroundColor                    : Gray
BranchNameLimit                           : 0
AfterForegroundColor                      : Yellow
DelimBackgroundColor                      : Black
BranchBehindStatusForegroundColor         : Red
AfterStashForegroundColor                 : Red
LocalDefaultStatusForegroundBrightColor   : Green
LocalDefaultStatusBackgroundColor         : Black
StashForegroundColor                      : Red
DelimForegroundColor                      : Yellow
TruncatedBranchSuffix                     : ...
FileAddedText                             : +
StashBackgroundColor                      : Black
BranchAheadStatusForegroundColor          : Green
BranchUntrackedSymbol                     :
BranchBehindStatusBackgroundColor         : Black
BranchAheadStatusBackgroundColor          : Black
AutoRefreshIndex                          : True
BeforeText                                :  [
BranchBehindStatusSymbol                  : ↓
EnableWindowTitle                         : posh~git ~
BranchBehindAndAheadStatusBackgroundColor : Black
BeforeIndexText                           :
EnableFileStatus                          : True
BeforeStashText                           :  (
FileConflictedText                        : !

It would be much easier to find related settings if we used an ordered dictionary which preserves insert order (not available in v2 though):

Name                           Value
----                           -----
DefaultForegroundColor         Gray
BeforeText                      [
BeforeForegroundColor          Yellow
BeforeBackgroundColor          Black
DelimText                       |
DelimForegroundColor           Yellow
DelimBackgroundColor           Black
AfterText                      ]
AfterForegroundColor           Yellow
AfterBackgroundColor           Black
FileAddedText                  +
FileModifiedText               ~
FileRemovedText                -
FileConflictedText             !
LocalDefaultStatusSymbol
LocalDefaultStatusForegroun... DarkGreen
LocalDefaultStatusForegroun... Green
LocalDefaultStatusBackgroun... Black
LocalWorkingStatusSymbol       !
LocalWorkingStatusForegroun... DarkRed
LocalWorkingStatusForegroun... Red
LocalWorkingStatusBackgroun... Black
LocalStagedStatusSymbol        ~
LocalStagedStatusForeground... Cyan
LocalStagedStatusBackground... Black
BranchUntrackedSymbol
BranchForegroundColor          Cyan
BranchBackgroundColor          Black
BranchGoneStatusSymbol         ×
BranchGoneStatusForegroundC... DarkCyan
BranchGoneStatusBackgroundC... Black
BranchIdenticalStatusToSymbol  ≡
BranchIdenticalStatusToFore... Cyan
BranchIdenticalStatusToBack... Black
BranchAheadStatusSymbol        ↑
BranchAheadStatusForeground... Green
BranchAheadStatusBackground... Black
BranchBehindStatusSymbol       ↓
BranchBehindStatusForegroun... Red
BranchBehindStatusBackgroun... Black
BranchBehindAndAheadStatusS... ↕
BranchBehindAndAheadStatusF... Yellow
BranchBehindAndAheadStatusB... Black
BeforeIndexText
BeforeIndexForegroundColor     DarkGreen
BeforeIndexForegroundBright... Green
BeforeIndexBackgroundColor     Black
IndexForegroundColor           DarkGreen
IndexForegroundBrightColor     Green
IndexBackgroundColor           Black
WorkingForegroundColor         DarkRed
WorkingForegroundBrightColor   Red
WorkingBackgroundColor         Black
EnableStashStatus              False
BeforeStashText                 (
BeforeStashBackgroundColor     Black
BeforeStashForegroundColor     Red
AfterStashText                 )
AfterStashBackgroundColor      Black
AfterStashForegroundColor      Red
StashBackgroundColor           Black
StashForegroundColor           Red
ShowStatusWhenZero             True
AutoRefreshIndex               True
BranchBehindAndAheadDisplay    Full
EnablePromptStatus             True
EnableFileStatus               True
RepositoriesInWhichToDisabl... {}
DescribeStyle
EnableWindowTitle              posh~git ~
Debug                          False
BranchNameLimit                0
TruncatedBranchSuffix          ...

And yeah, the ordered dictionary is a different type than a PSCustomObject but you can dot the kv pairs in PowerShell as if it were a property e.g. $GitPromptSettings.EnableFileStatus.

@drawfour
Copy link
Contributor

PowerShell v3 has an [ordered] property for PSObject properties, so you can use that too.

https://connect.microsoft.com/PowerShell/feedback/details/679963/new-object-psobject-property-should-maintain-the-order-of-the-properties

@rkeithhill
Copy link
Collaborator Author

rkeithhill commented Dec 31, 2016

Yup, that is exactly what I prototyped the above with. But as you point out, [ordered] isn't available in PS v2 so this change will have to wait until 0.7.0 has been released and we start work on 1.0.0 which will definitely drop support for v2 (and maybe even v3 and 4).

@rkeithhill rkeithhill modified the milestone: v1.0 Dec 31, 2016
@JayBazuzi
Copy link
Collaborator

What about grouping related items?

PS> $GitPromptSettings.Colors.Stash.Background = Red

@dahlbyk dahlbyk added this to the v1.0 milestone Jan 1, 2017
@dahlbyk
Copy link
Owner

dahlbyk commented Jan 1, 2017

I'm inclined to leave as-is for 0.x and then move to [ordered] for 1.x with either a cleanup of the property names (e.g. BranchIdenticalStatusTo* should be BranchIdenticalToStatus*) or a shift to grouping.

Pondering the grouping... what if we defined a type to encapsulate the common text + foreground + background color pattern. That type's ToString() could even be configured to return the ANSI colorized string so dumping $GitPromptSettings.Format would show the colorized output.

@rkeithhill
Copy link
Collaborator Author

Agreed on 0.x.

One advantage of using [ordered] for 1.x is that I don't think it would be a breaking change - not that I'm necessarily opposed to a breaking change for 1.x if the result is a lot better. :-)

what if we defined a type to encapsulate the common text + foreground + background color pattern

I like that idea but I'm not sure about ToString display a completed prompt. How would that work with the Write-GitStatus decomposition as suggested in #345?

I could see a function like Write-GitBranchStatus $GitStatus having optional Fore/BackgroundColor parameters that default to the corresponding setting in $GitPromptSettings.

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 2, 2017

I like that idea but I'm not sure about ToString display a completed prompt. How would that work with the Write-GitStatus decomposition as suggested in #345?

I more mean for each of the components, e.g. $GitPromptSettings.Format.BranchStatusIdenticalTo.ToString() would return the colorized identical-to symbol, and dumping $GitPromptSettings.Format would show something like this (but with colors):

Before                              :  [
BranchStatusAhead                   : ↑
BranchStatusBehindAndAhead          : ↕
BranchStatusBehind                  : ↓
BranchStatusIdenticalTo             : ≡
BranchStatusUntracked               :  
BeforeIndex                         :
Index                               : !0 +0 ~0 -0
Delim                               :  |
Working                             : !0 +0 ~0 -0
LocalDefaultStatus                  :  
LocalStagedStatus                   : ~
LocalWorkingStatus                  : !
BeforeStash                         :  (
AfterStash                          : )
After                               : ]

Of course, if we go the composition route proposed in #345 then format/color config might go away. Then again, maybe not - I expect more folks wish to just change colors than rearrange the whole prompt?

@rkeithhill
Copy link
Collaborator Author

Gotcha. Probably just need to prototype something up after 0.7. It would be nice to have the above for simple customization and #345 for more significant customization.

@lzybkr
Copy link
Collaborator

lzybkr commented Jan 2, 2017

.Net 3.5 has System.Collections.Specialized.OrderedDictionary, so it's possible to use that in 0.7 if you want - the syntax won't be as friendly as [ordered] though.

@rkeithhill
Copy link
Collaborator Author

Partially addressed (ordering) by PR #382. By using a PSCustomObject the value can still be accessed using property syntax as if it were a PSObject with dedicated properties when in fact it is a hashtable (which preserves definition order on v5 and higher).

@dahlbyk dahlbyk modified the milestones: v1.0, v0.7 Feb 1, 2017
@isochronous
Copy link

isochronous commented Feb 9, 2017

Also, unless I'm missing something, the readme.md on this project is saying that the "most common" customization to the prompt is on a property that doesn't seem to exist:

You can customize the posh-git prompt or define your own custom prompt function. The most common customization for the posh-git provided prompt is to make it span two lines which can be done with the following command:

$GitPromptSettings.DefaultPromptSuffix = 'n$(''>'' * ($nestedPromptLevel + 1)) '

There's no DefaultPromptSuffix property on the GitPromptSettings object.

@rkeithhill
Copy link
Collaborator Author

The master branch of this repo is used for development and represents the state of the next version - 0.7.0. This version is very close to being finished and published, hopefully by early next week.

@nickcox
Copy link

nickcox commented Feb 9, 2017

So should this work when installed using ps-get?

If I do:

Install-Module posh-git -Scope CurrentUser
Import-Module posh-git
$GitPromptSettings.DefaultPromptSuffix = 'n$(''>'' * ($nestedPromptLevel + 1)) '

I get an error:
Exception setting "DefaultPromptSuffix": "The property 'DefaultPromptSuffix' cannot be found on this object. Verify that the property exists and can be set."

@rkeithhill
Copy link
Collaborator Author

should this work

No, because we haven't released 0.7.0 which contains this change. Hang tight, should be released sometime early next week (I hope).

@dahlbyk dahlbyk changed the title For 1.0.0 if we stick with GitPromptSettings as a globl object let's use an ordered dictionary Replace or improve $GitPromptSettings Feb 17, 2017
@dahlbyk
Copy link
Owner

dahlbyk commented Feb 17, 2017

Refactoring this issue to represent the general need to improve the config situation. Ideas:

  1. Use ANSI strings to simplify color config
  2. Support ~/.posh-git.yml or equivalent
  3. Use Git config for posh-git config (git config posh-git.Whatever)
  4. Supply a function that can be called with a parameter for each config option
  5. Some combination of these

@dahlbyk dahlbyk mentioned this issue Feb 17, 2017
13 tasks
@rkeithhill
Copy link
Collaborator Author

I lean towards commands like Get/Set-PoshGitPromptOption (similar to PSReadLine's Get/Set-PSReadlineOption) but depending on whether we support only PS v5 and higher, we might also work PS classes into the mix to group related settings.

@rkeithhill
Copy link
Collaborator Author

Addressed by PR #513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants