Using Backspace or Del Keys render as black box ! #19159

Closed
opened 2026-01-31 06:35:27 +00:00 by claunia · 6 comments
Owner

Originally created by @AnasTaherGit on GitHub (Dec 30, 2022).

Windows Terminal version

1.15.3466.0

Windows build number

No response

Other Software

No response

Steps to reproduce

I don't know the source of the bug it's just happening for me ! i just press backspace or del keys and it render as black box
and it happens only in powershell

Expected Behavior

When i press backspace or del key i expect to see blank space with my background in it

Actual Behavior

I got a black box and it appears as the whole background changed since if i rewrite a lettre it rendered on top of the black box

image

Originally created by @AnasTaherGit on GitHub (Dec 30, 2022). ### Windows Terminal version 1.15.3466.0 ### Windows build number _No response_ ### Other Software _No response_ ### Steps to reproduce I don't know the source of the bug it's just happening for me ! i just press backspace or del keys and it render as black box and it happens only in powershell ### Expected Behavior When i press backspace or del key i expect to see blank space with my background in it ### Actual Behavior I got a black box and it appears as the whole background changed since if i rewrite a lettre it rendered on top of the black box ![image](https://user-images.githubusercontent.com/13611023/210067530-9e81b7cc-32d1-41bd-97c7-1823c20116c6.png)
Author
Owner

@237dmitry commented on GitHub (Dec 30, 2022):

I think this is incorrect function prompt {} in powershell.

@237dmitry commented on GitHub (Dec 30, 2022): I think this is incorrect `function prompt {}` in powershell.
Author
Owner

@AnasTaherGit commented on GitHub (Dec 30, 2022):

Here is the script of the prompt function i can't see where is the problem

 #store if the last command was successful
    $lastCommandSuccess = $?
    #store the last exit code for restore
    $realLASTEXITCODE = $global:LASTEXITCODE
    $omp = "C:/Users/cawoo/AppData/Local/oh-my-posh/oh-my-posh.exe"
    $config, $cleanPWD, $cleanPSWD = Get-PoshContext
    if ($env:POSH_TRANSIENT -eq $true) {
        $standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --print-transient 2>&1)
        $standardOut -join "`n"
        $env:POSH_TRANSIENT = $false
        return
    }
    $errorCode = 0
    Initialize-ModuleSupport
    Set-PoshContext
    if ($lastCommandSuccess -eq $false) {
        #native app exit code
        if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) {
            $errorCode = $realLASTEXITCODE
        }
        else {
            $errorCode = 1
        }
    }

    # read stack count from current stack(if invoked from profile=right value,otherwise use the global variable set in Set-PoshPrompt(stack scoped to module))
    $stackCount = (Get-Location -stack).Count
    try {
        if ($global:omp_global_sessionstate -ne $null) {
            $stackCount = ($global:omp_global_sessionstate).path.locationstack('').count
        }
    }
    catch {}

    $executionTime = -1
    $history = Get-History -ErrorAction Ignore -Count 1
    if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime -and $global:omp_lastHistoryId -ne $history.Id) {
        $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
        $global:omp_lastHistoryId = $history.Id
    }
    $terminalWidth = $Host.UI.RawUI.WindowSize.Width
    $standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" --terminal-width=$terminalWidth 2>&1)
    # make sure PSReadLine knows we have a multiline prompt
    $extraLines = $standardOut.Count - 1
    if ($extraLines -gt 0) {
        Set-PSReadlineOption -ExtraPromptLineCount $extraLines
    }
    # the output can be multiline, joining these ensures proper rendering by adding line breaks with `n
    $standardOut -join "`n"
    $global:LASTEXITCODE = $realLASTEXITCODE
    #remove temp variables
    Remove-Variable realLASTEXITCODE -Confirm:$false
    Remove-Variable lastCommandSuccess -Confirm:$false
@AnasTaherGit commented on GitHub (Dec 30, 2022): Here is the script of the prompt function i can't see where is the problem ``` #store if the last command was successful $lastCommandSuccess = $? #store the last exit code for restore $realLASTEXITCODE = $global:LASTEXITCODE $omp = "C:/Users/cawoo/AppData/Local/oh-my-posh/oh-my-posh.exe" $config, $cleanPWD, $cleanPSWD = Get-PoshContext if ($env:POSH_TRANSIENT -eq $true) { $standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --print-transient 2>&1) $standardOut -join "`n" $env:POSH_TRANSIENT = $false return } $errorCode = 0 Initialize-ModuleSupport Set-PoshContext if ($lastCommandSuccess -eq $false) { #native app exit code if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) { $errorCode = $realLASTEXITCODE } else { $errorCode = 1 } } # read stack count from current stack(if invoked from profile=right value,otherwise use the global variable set in Set-PoshPrompt(stack scoped to module)) $stackCount = (Get-Location -stack).Count try { if ($global:omp_global_sessionstate -ne $null) { $stackCount = ($global:omp_global_sessionstate).path.locationstack('').count } } catch {} $executionTime = -1 $history = Get-History -ErrorAction Ignore -Count 1 if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime -and $global:omp_lastHistoryId -ne $history.Id) { $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds $global:omp_lastHistoryId = $history.Id } $terminalWidth = $Host.UI.RawUI.WindowSize.Width $standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" --terminal-width=$terminalWidth 2>&1) # make sure PSReadLine knows we have a multiline prompt $extraLines = $standardOut.Count - 1 if ($extraLines -gt 0) { Set-PSReadlineOption -ExtraPromptLineCount $extraLines } # the output can be multiline, joining these ensures proper rendering by adding line breaks with `n $standardOut -join "`n" $global:LASTEXITCODE = $realLASTEXITCODE #remove temp variables Remove-Variable realLASTEXITCODE -Confirm:$false Remove-Variable lastCommandSuccess -Confirm:$false ```
Author
Owner

@237dmitry commented on GitHub (Dec 30, 2022):

I think you could try a powershell without the third party modules. What behavior if you run powershell -nop? There are too many questions for oh-my-posh.

@237dmitry commented on GitHub (Dec 30, 2022): I think you could try a powershell without the third party modules. What behavior if you run `powershell -nop`? There are too many questions for oh-my-posh.
Author
Owner

@AnasTaherGit commented on GitHub (Dec 30, 2022):

I get the same behavior with -nop flag

image

@AnasTaherGit commented on GitHub (Dec 30, 2022): I get the same behavior with -nop flag ![image](https://user-images.githubusercontent.com/13611023/210092200-50f240c0-eceb-4c6d-85a0-68993c2ec728.png)
Author
Owner

@j4james commented on GitHub (Dec 31, 2022):

I believe this is the result of an old PSReadLine bug. You can see a similar report in #6767. If that is the case, you probably just need to upgrade the PSReadLine module to get it working correctly.

@j4james commented on GitHub (Dec 31, 2022): I believe this is the result of an old PSReadLine bug. You can see a similar report in #6767. If that is the case, you probably just need to upgrade the PSReadLine module to get it working correctly.
Author
Owner

@zadjii-msft commented on GitHub (Jan 3, 2023):

Yea this is definitely an old PSReadline issue. Updating psreadline (and/or powershell to pwsh 7) will fix this.

@zadjii-msft commented on GitHub (Jan 3, 2023): Yea this is definitely an old PSReadline issue. Updating psreadline (and/or powershell to pwsh 7) will fix this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19159