diff --git a/docs/docs/installation.mdx b/docs/docs/installation.mdx index 2767ce23..53fbd8f5 100644 --- a/docs/docs/installation.mdx +++ b/docs/docs/installation.mdx @@ -84,10 +84,30 @@ Edit `$PROFILE` in your preferred PowerShell version and add the following lines ```powershell [ScriptBlock]$Prompt = { - $realLASTEXITCODE = $global:LASTEXITCODE - & "C:\tools\oh-my-posh.exe" -config "~/downloadedtheme.json" -error $realLASTEXITCODE -pwd $PWD - $global:LASTEXITCODE = $realLASTEXITCODE - Remove-Variable realLASTEXITCODE -Confirm:$false + $realLASTEXITCODE = $global:LASTEXITCODE + if ($realLASTEXITCODE -isnot [int]) { + $realLASTEXITCODE = 0 + } + $startInfo = New-Object System.Diagnostics.ProcessStartInfo + $startInfo.FileName = "C:\tools\oh-my-posh.exe" + $config = $global:PoshSettings.Theme + $startInfo.Arguments = "-config C:\Users\User\Downloads\downloadedtheme.json -pwd $PWD -error $realLASTEXITCODE" + $startInfo.Environment["TERM"] = "xterm-256color" + $startInfo.CreateNoWindow = $true + $startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8 + $startInfo.RedirectStandardOutput = $true + $startInfo.UseShellExecute = $false + if ($PWD.Provider.Name -eq "FileSystem") { + $startInfo.WorkingDirectory = $PWD + } + $process = New-Object System.Diagnostics.Process + $process.StartInfo = $startInfo + $process.Start() | Out-Null + $standardOut = $process.StandardOutput.ReadToEnd() + $process.WaitForExit() + $standardOut + $global:LASTEXITCODE = $realLASTEXITCODE + Remove-Variable realLASTEXITCODE -Confirm:$false } Set-Item -Path Function:prompt -Value $Prompt -Force ``` diff --git a/engine.go b/engine.go index 2badf4b2..2d0ad5c2 100644 --- a/engine.go +++ b/engine.go @@ -122,7 +122,7 @@ func (e *engine) render() { for _, block := range e.settings.Blocks { // if line break, append a line break if block.Type == LineBreak { - fmt.Print(e.renderer.lineBreak()) + fmt.Print("\n") continue } if block.VerticalOffset != 0 { diff --git a/packages/powershell/oh-my-posh/oh-my-posh.psm1 b/packages/powershell/oh-my-posh/oh-my-posh.psm1 index abb63b6f..5c5d14c4 100644 --- a/packages/powershell/oh-my-posh/oh-my-posh.psm1 +++ b/packages/powershell/oh-my-posh/oh-my-posh.psm1 @@ -23,19 +23,6 @@ if (!$IsWindows) { $executable = Get-PoshCommand Invoke-Expression -Command "chmod +x $executable" } -if ($IsWindows) { - # When this is not set, outputted fonts aren't rendered correctly in some terminals for the prompt function - # 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 -} function Set-PoshContext {} @@ -58,10 +45,28 @@ function Set-PoshPrompt { [ScriptBlock]$Prompt = { $realLASTEXITCODE = $global:LASTEXITCODE - $poshCommand = Get-PoshCommand + if ($realLASTEXITCODE -isnot [int]) { + $realLASTEXITCODE = 0 + } + $startInfo = New-Object System.Diagnostics.ProcessStartInfo + $startInfo.FileName = Get-PoshCommand $config = $global:PoshSettings.Theme + $startInfo.Arguments = "-config $config -pwd $PWD -error $realLASTEXITCODE" + $startInfo.Environment["TERM"] = "xterm-256color" + $startInfo.CreateNoWindow = $true + $startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8 + $startInfo.RedirectStandardOutput = $true + $startInfo.UseShellExecute = $false + if ($PWD.Provider.Name -eq "FileSystem") { + $startInfo.WorkingDirectory = $PWD + } + $process = New-Object System.Diagnostics.Process + $process.StartInfo = $startInfo Set-PoshContext - & $poshCommand -config $config -error $realLASTEXITCODE -pwd $PWD + $process.Start() | Out-Null + $standardOut = $process.StandardOutput.ReadToEnd() + $process.WaitForExit() + $standardOut $global:LASTEXITCODE = $realLASTEXITCODE Remove-Variable realLASTEXITCODE -Confirm:$false } diff --git a/renderer.go b/renderer.go index 8cf5aa80..3f783828 100755 --- a/renderer.go +++ b/renderer.go @@ -130,13 +130,6 @@ func (r *Renderer) lenWithoutANSI(str string) int { return count } -func (r *Renderer) lineBreak() string { - if r.shell == "pwsh" { - return "\x1b[1000C " - } - return "\n" -} - func (r *Renderer) carriageForward() string { return fmt.Sprintf(r.formats.left, 1000) }