From 9627b905e6b7122b78a372a08fe8065855cebbfb Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 12 Oct 2020 16:23:05 +0200 Subject: [PATCH] fix: catch error setting encoding outside of console --- packages/powershell/oh-my-posh/oh-my-posh.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/powershell/oh-my-posh/oh-my-posh.psm1 b/packages/powershell/oh-my-posh/oh-my-posh.psm1 index 28b78e8f..677dcfdd 100644 --- a/packages/powershell/oh-my-posh/oh-my-posh.psm1 +++ b/packages/powershell/oh-my-posh/oh-my-posh.psm1 @@ -25,7 +25,13 @@ if (!$IsWindows) { } if ($IsWindows) { # When this is not set, outputted fonts aren't rendered correctly in some terminals for the prompt function - [console]::OutputEncoding = New-Object System.Text.UTF8Encoding + # It can also fail when we're not running in a console (and then, well, you're on your own) + try { + [console]::OutputEncoding = New-Object System.Text.UTF8Encoding + } + catch { + Write-Host "oh-my-posh: unable to set output encoding to UTF8, fonts might be rendered incorrectly." + } # Not running it beforehand in the terminal will fail the prompt somehow $poshCommand = Get-PoshCommand & $poshCommand | Out-Null