diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2020-10-19 19:52:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 13:52:15 -0400 |
commit | daf7976f9dfa35f816b8dafb8e707b9ee7df0908 (patch) | |
tree | 2cca5673e8c1d451a3af8f793dc544d233070bf1 /src | |
parent | f9bed976c1f8da13e907c796cce940e8a4ddfa77 (diff) |
fix(pwsh): preserve original console encondings (#1810)
Diffstat (limited to 'src')
-rw-r--r-- | src/init/starship.ps1 | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/init/starship.ps1 b/src/init/starship.ps1 index f96b67d2b..64f524c2e 100644 --- a/src/init/starship.ps1 +++ b/src/init/starship.ps1 @@ -1,7 +1,5 @@ #!/usr/bin/env pwsh -# Starship assumes UTF-8 -[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 function global:prompt { $origDollarQuestion = $global:? $origLastExitCode = $global:LASTEXITCODE @@ -18,6 +16,9 @@ function global:prompt { # doesn't show the last command as a failure (because it had a non-zero exit code). $lastExitCodeForPrompt = if ($origLastExitCode) { $origLastExitCode } else { 0 } + # Save old output encoding and set it to UTF-8 + $origOutputEncoding = [Console]::OutputEncoding + [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 if ($lastCmd = Get-History -Count 1) { $duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalMilliseconds) # & ensures the path is interpreted as something to execute @@ -25,6 +26,8 @@ function global:prompt { } else { $out = @(&::STARSHIP:: prompt "--path=$current_directory" --status=$lastExitCodeForPrompt --jobs=$jobs) } + # Restore old output encoding + [Console]::OutputEncoding = $origOutputEncoding # Convert stdout (array of lines) to expected return type string # `n is an escaped newline |