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

Git prompts not displayed properly #389

Closed
taroxd opened this issue Feb 1, 2017 · 13 comments · Fixed by #397
Closed

Git prompts not displayed properly #389

taroxd opened this issue Feb 1, 2017 · 13 comments · Fixed by #397
Milestone

Comments

@taroxd
Copy link

taroxd commented Feb 1, 2017

System Details

  • posh-git version: 0.7.0 (commit 10f136f)
  • PowerShell version: 5.1.14393.693
  • git version 2.11.0.windows.1
  • OS: Microsoft Windows NT 10.0.14393.0

Issue Description

Git prompts are not displayed properly in my powershell. There are no such issues in some older versions of posh-git.

image

My powershell profile:

# Load posh git
Import-Module 'absolute\path\to\posh-git\src\posh-git.psd1'

# Customize git prompt
$s = $Global:GitPromptSettings
$s.BranchUntrackedSymbol = $null
$s.BranchIdenticalStatusToSymbol = $null
$s.BranchAheadStatusSymbol = $null
$s.BranchBehindStatusSymbol = $null
$s.BranchBehindAndAheadStatusSymbol = $null
$s.BranchBehindAndAheadDisplay = "Minimal"
$s.LocalWorkingStatusSymbol = $null
$s.LocalStagedStatusSymbol = $null

And the issue has nothing to do with my customizations. I tried to remove my customizions, but the issue persists.
If I do not import posh-git, the prompts will be displayed properly (without git prompts).

@rkeithhill
Copy link
Collaborator

rkeithhill commented Feb 1, 2017

Interesting. Can you post your prompt function here? Execute (gcm prompt).Definition | Out-Clipboard from PowerShell and then paste the results here. Also what font is your console using?

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 1, 2017

Wow, I have no idea what this could be. If you scroll up/down do the blank spaces move with the text?

@taroxd
Copy link
Author

taroxd commented Feb 2, 2017

@rkeithhill

        if ($GitPromptSettings.DefaultPromptEnableTiming) {
            $sw = [System.Diagnostics.Stopwatch]::StartNew()
        }
        $origLastExitCode = $global:LASTEXITCODE

        # A UNC path has no drive so it's better to use the ProviderPath e.g. "\\server\share".
        # However for any path with a drive defined, it's better to use the Path property.
        # In this case, ProviderPath is "\LocalMachine\My"" whereas Path is "Cert:\LocalMachine\My".
        # The latter is more desirable.
        $pathInfo = $ExecutionContext.SessionState.Path.CurrentLocation
        $currentPath = if ($pathInfo.Drive) { $pathInfo.Path } else { $pathInfo.ProviderPath }

        # File system paths are case-sensitive on Linux and case-insensitive on Windows and macOS
        if (($PSVersionTable.PSVersion.Major -ge 6) -and $IsLinux) {
            $stringComparison = [System.StringComparison]::Ordinal
        }
        else {
            $stringComparison = [System.StringComparison]::OrdinalIgnoreCase
        }

        # Abbreviate path by replacing beginning of path with ~ *iff* the path is in the user's home dir
        if ($currentPath -and $currentPath.StartsWith($Home, $stringComparison))
        {
            $currentPath = "~" + $currentPath.SubString($Home.Length)
        }

        # Write the abbreviated current path
        Write-Host $currentPath -NoNewline

        # Write the Git status summary information
        Write-VcsStatus

        # If stopped in the debugger, the prompt needs to indicate that in some fashion
        $debugMode = (Test-Path Variable:/PSDebugContext) -or [runspace]::DefaultRunspace.Debugger.InBreakpoint
        $promptSuffix = if ($debugMode) { $GitPromptSettings.DefaultPromptDebugSuffix } else { $GitPromptSettings.DefaultPromptSuffix }

        # If user specifies $null or empty string, set to ' ' to avoid "PS>" unexpectedly being displayed
        if (!$promptSuffix) {
            $promptSuffix = ' '
        }

        $expandedPromptSuffix = $ExecutionContext.SessionState.InvokeCommand.ExpandString($promptSuffix)

        # If prompt timing enabled, display elapsed milliseconds
        if ($GitPromptSettings.DefaultPromptEnableTiming) {
            $sw.Stop()
            $elapsed = $sw.ElapsedMilliseconds
            Write-Host " ${elapsed}ms" -NoNewline
        }

        $global:LASTEXITCODE = $origLastExitCode
        $expandedPromptSuffix

font: Terminal (size: 8 x 16)

@dahlbyk
After scrolling up/down, the blank spaces disappear.
Also, selecting the texts make these blank spaces disappear, too.

I tried another font and it works normally. However I prefer the font Terminal.

And, I can show you the result after changing the font size.
image

@taroxd
Copy link
Author

taroxd commented Feb 2, 2017

I find out that the issue was introduced in 846a4ec with the help of git bisect.

The locale of my OS is Simplified Chinese, and I am using code page 936 (ANSI/OEM 简体中文 GBK) for my powershell. I would not like to alter my code page because there would be more display issues in powershell if I did, as a typical Chinese user.
( However I am definitely hoping that Microsoft will always use UTF-8 in their products ).

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 2, 2017

I find out that the issue was introduced in 846a4ec with the help of git bisect.

❤️ ❗️

The final version of #359 moved the encoding set/reset into `Invoke-Utf8ConsoleCommand. You might try fiddling in there?

The locale of my OS is Simplified Chinese, and I am using code page 936 (ANSI/OEM 简体中文 GBK) for my powershell. I would not like to alter my code page because there would be more display issues in powershell if I did, as a typical Chinese user.
( However I am definitely hoping that Microsoft will always use UTF-8 in their products ).

Completely understood. http://stackoverflow.com/questions/22349139/utf-8-output-from-powershell suggests our current solution might not be the correct one. I wonder if @LeeHolmes could weigh in on a better approach to handling the fact that git.exe output is always UTF-8?

@dahlbyk dahlbyk added this to the v0.7 milestone Feb 2, 2017
@taroxd
Copy link
Author

taroxd commented Feb 2, 2017

I removed this line in my local version as a workaround, and it works well now. Hopefully a better approach can be found.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 2, 2017

@taroxd the problem we are trying to solve is handling branch names (and file paths, etc) with non-ASCII characters (e.g. git checkout -b utf8•branch). I assume your prompt on such a branch shows strange characters now?

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 2, 2017

@taroxd also, what do you get from [Console]::OutputEncoding?

@taroxd
Copy link
Author

taroxd commented Feb 3, 2017

Yes, it does, after I removed the line that handles encoding. But I probably won't encounter such branch names when I use git.
There are currently no problem about non-ASCII file paths.

image

The result of [Console]::OutputEncoding:

image

BodyName          : gb2312
EncodingName      : 简体中文(GB2312)
HeaderName        : gb2312
WebName           : gb2312
WindowsCodePage   : 936
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 936

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 3, 2017

@taroxd give #397 a try. I think it sufficiently excludes you from the override without breaking UTF-8 for folks who are still using ASCII.

@taroxd
Copy link
Author

taroxd commented Feb 3, 2017

Thanks, it works.

@be5invis
Copy link

@taroxd Have you tried to change the UI font to something not raster?
Like Inziu Iosevka?

@taroxd
Copy link
Author

taroxd commented May 28, 2017

@be5invis
I am not familiar with font, so I do not understand what raster means.

I have been using Microsoft YaHei Mono (which you made years ago if I remember correctly) since Creators Update.
While some glitches may occur when selecting lines containing Chinese characters, this is a bug of windows command line window (or the font?) and has nothing to do with posh-git.
Posh-git works nicely for me after #397, no matter which font I choose.

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 a pull request may close this issue.

4 participants