mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(pwsh): force session to UTF8
This commit is contained in:
parent
6379982c3b
commit
ce5a9d6b76
|
@ -3,6 +3,10 @@
|
|||
Generates the prompt before each line in the console
|
||||
#>
|
||||
|
||||
# Powershell doesn't default to UTF8 just yet, so we're forcing it as there are too many problems
|
||||
# that pop up when we don't
|
||||
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
|
||||
|
||||
function Get-PoshCommand {
|
||||
if ($IsMacOS) {
|
||||
return "$PSScriptRoot/bin/posh-darwin-amd64"
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# Powershell doesn't default to UTF8 just yet, so we're forcing it as there are too many problems
|
||||
# that pop up when we don't
|
||||
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
|
||||
|
||||
$global:PoshSettings = New-Object -TypeName PSObject -Property @{
|
||||
Theme = "";
|
||||
}
|
||||
|
@ -38,16 +42,11 @@ function global:Set-PoshGitStatus {
|
|||
if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime) {
|
||||
$executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
|
||||
}
|
||||
# Save current encoding and swap for UTF8
|
||||
$originalOutputEncoding = [Console]::OutputEncoding
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$omp = "::OMP::"
|
||||
$config = $global:PoshSettings.Theme
|
||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
||||
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
||||
$standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --config="$config" 2>&1)
|
||||
# Restore initial encoding
|
||||
[Console]::OutputEncoding = $originalOutputEncoding
|
||||
# the ouput can be multiline, joining these ensures proper rendering by adding line breaks with `n
|
||||
$standardOut -join "`n"
|
||||
Set-PoshGitStatus
|
||||
|
@ -59,14 +58,10 @@ function global:Set-PoshGitStatus {
|
|||
Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||
|
||||
function global:Write-PoshDebug {
|
||||
$originalOutputEncoding = [Console]::OutputEncoding
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$omp = "::OMP::"
|
||||
$config = $global:PoshSettings.Theme
|
||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
||||
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
||||
$standardOut = @(&$omp --error=1337 --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time=9001 --config="$config" --debug 2>&1)
|
||||
$standardOut
|
||||
# Restore initial encoding
|
||||
[Console]::OutputEncoding = $originalOutputEncoding
|
||||
$standardOut -join "`n"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue