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

Improved WindowTitle customization experience #541

Merged
merged 7 commits into from
Jan 29, 2018

Conversation

rkeithhill
Copy link
Collaborator

@rkeithhill rkeithhill commented Jan 25, 2018

v1 fix for #537

Needs more Pester tests. Also, I think we might want to keep EnableWindowTitle as a simple bool. If you disable the WindowTitle by setting it to $null, you lose the original definition.

Also you made a comment about evaluating the WindowTitle scriptblock during prompt eval. It does seem a bit unusual that we change the WindowTitle in the Write-GitStatus function. Is the proposal to move the setting of the host WindowTitle to the built-in prompt?

BTW there was some code we used to determine WindowTitleSupported that I've thought was circumspect for a while. This gave me a chance to take a better (I hope) approach.

Needs more Pester tests.
Copy link
Owner

@dahlbyk dahlbyk left a comment

Choose a reason for hiding this comment

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

Also you made a comment about evaluating the WindowTitle scriptblock during prompt eval. It does seem a bit unusual that we change the WindowTitle in the Write-GitStatus function. Is the proposal to move the setting of the host WindowTitle to the built-in prompt?

Yes, let's think of it as a title-customization feature with Git support, rather than a Git title customization feature. To that end, our default WindowTitle should do something reasonable if $GitStatus is $null.

BTW there was some code we used to determine WindowTitleSupported that I've thought was circumspect for a while. This gave me a chance to take a better (I hope) approach.

💯

$WindowTitleSupported = $false
try {
$global:PreviousWindowTitle = $Host.UI.RawUI.WindowTitle
$newTitle = "$origTitle "
Copy link
Owner

Choose a reason for hiding this comment

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

Should this be "$PreviousWindowTitle "?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doh! Yes it should be. Thanks. I'll fix it tonight.

[string]$DescribeStyle = ''
[psobject]$EnableWindowTitle = 'posh~git ~ '
[string]$DescribeStyle = ''
[bool]$EnableWindowTitle = $true
Copy link
Owner

Choose a reason for hiding this comment

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

Also, I think we might want to keep EnableWindowTitle as a simple bool. If you disable the WindowTitle by setting it to $null, you lose the original definition.

I'm not too worried about this, since resetting is as simple as opening a new shell. Fewer settings seems better than many.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, we have reduced the number of "top-level" settings a lot. :-) But I don't feel that strongly about this.

@dahlbyk dahlbyk changed the title WIP - initial, working commit Improved WindowTitle customization experience Jan 25, 2018
@rkeithhill
Copy link
Collaborator Author

rkeithhill commented Jan 26, 2018

This last commit cleans up GitPrompt.ps1 real nice. No "extraneous" code in it now. BTW, in the $GitStatus is null case as well as the case where the user's WindowTitle scriptblock/string generates an error, we fall back to the $global:PreviousWindowTitle.

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 26, 2018

BTW, in the $GitStatus is null case as well as the case where the user's WindowTitle scriptblock/string generates an error, we fall back to the $global:PreviousWindowTitle.

Is that what we want, though? It seems more useful if this feature can be used to customize the window title at all times (e.g. showing $PID), not just in a posh-git context. Falling back to $global:PreviousWindowTitle should only be necessary if the scriptblock/string comes back errored or empty.

@rkeithhill
Copy link
Collaborator Author

rkeithhill commented Jan 26, 2018

Is that what we want, though?

I'm definitely open to making changes here. It always seemed a bit odd to me that the title swapped to the default/startup text in non-Git dirs. It would complicate the default scriptblock a bit but I think that is OK. I could see it being something like this:

{
    param($GitStatus, [bool]$IsAdmin) 
    "$(if ($IsAdmin) {'Administrator: '})$(if ($GitStatus) {"posh~git ~ $($GitStatus.RepoName) [$($GitStatus.Branch)] "})PowerShell $(if ([IntPtr]::Size -eq 8) {'x64'} else {'x86'}) $($PSVersionTable.PSVersion) ($PID)"
} 

That gives title bar text like this outside a git repo (as admin):

Administrator: PowerShell x64 5.1.16299.98 (33624)

and inside a Git repo (not as admin):

posh~git ~ vscode-powershell [master] PowerShell x64 5.1.16299.98 (33624)

When we display the posh-git info, perhaps we need another separator before PowerShell:

posh~git ~ vscode-powershell [master] ~ PowerShell x64 5.1.16299.98 (33624)

Thoughts? The x64/x86 info is of debatable value and I could easily be convinced not to add it.

@rkeithhill
Copy link
Collaborator Author

rkeithhill commented Jan 28, 2018

I removed the x64/x86 bit for now. BTW you have to set $GitPromptSettings.WindowTitle to $null to disable it. Perhaps we should allow $false, 0 and empty string to disable as well?

BTW I have an updated CHANGELOG I'll submit in a different PR once this PR has been merged.

@rkeithhill
Copy link
Collaborator Author

rkeithhill commented Jan 29, 2018

Thanks. I think that is what folks will expect. I can't think of any real user scenarios where someone would want to set their title bar to 0 or "" or $false. And if they did, they can set $host.UI.RawUI.WindowTitle directly.

@dahlbyk dahlbyk merged commit d55d962 into develop Jan 29, 2018
@dahlbyk dahlbyk deleted the rkeithhill/refactor-window-title branch January 29, 2018 22:14
@dahlbyk
Copy link
Owner

dahlbyk commented Jan 29, 2018

Nice work! I'll see about back-porting for 0.7.2.

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

Successfully merging this pull request may close these issues.

2 participants