fix: ensure correct encoding for pwsh

resolves 
This commit is contained in:
Jan De Dobbeleer 2021-01-17 13:08:08 +01:00 committed by Jan De Dobbeleer
parent 8e1d38f053
commit e26326001e

View file

@ -36,26 +36,16 @@ function Set-GitStatus {
if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime) { if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime) {
$executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
} }
# Save current encoding and swap for UTF8
$startInfo = New-Object System.Diagnostics.ProcessStartInfo $originalOutputEncoding = [Console]::OutputEncoding
$startInfo.FileName = "::OMP::" [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$omp = "::OMP::"
$config = $global:PoshSettings.Theme $config = $global:PoshSettings.Theme
$cleanPWD = $PWD.ProviderPath.TrimEnd("\") $cleanPWD = $PWD.ProviderPath.TrimEnd("\")
$cleanPSWD = $PWD.ToString().TrimEnd("\") $cleanPSWD = $PWD.ToString().TrimEnd("\")
$startInfo.Arguments = "--config=""$config"" --error=$errorCode --pwd=""$cleanPWD"" --pswd=""$cleanPSWD"" --execution-time=$executionTime" $standardOut = @(&$omp "--config=$config" "--error=$errorCode" "--pwd=$cleanPWD" "--pswd=$cleanPSWD" "--execution-time=$executionTime")
$startInfo.Environment["TERM"] = "xterm-256color" # Restore initial encoding
$startInfo.CreateNoWindow = $true [Console]::OutputEncoding = $originalOutputEncoding
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
if ($PWD.Provider.Name -eq 'FileSystem') {
$startInfo.WorkingDirectory = $PWD.ProviderPath
}
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start() | Out-Null
$standardOut = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
$standardOut $standardOut
Set-GitStatus Set-GitStatus
$global:LASTEXITCODE = $realLASTEXITCODE $global:LASTEXITCODE = $realLASTEXITCODE