microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.51k stars 8.31k forks source link

Cannot scroll up after couple time open and exit neovim #17739

Closed radiaku closed 2 months ago

radiaku commented 2 months ago

Windows Terminal version

1.20.11781.0

Windows build number

10.0.22631.4037

Other Software

Neovim 0.10.1 Powershell 7.4.4 oh-my-posh 23.6.3

Steps to reproduce

Opening nvim editing file multiple file, exit. then running nvim and then exit. couple times. I can scroll up but its become scroll history

Expected Behavior

scroll to up screen

Actual Behavior

becoming scroll up command line ( history )

check the video,

https://github.com/user-attachments/assets/009224fe-a452-401f-b9d9-b087126fcff6

this my $profile

Set-Alias -Name nvimq -Value "C:\neovimqt\bin\nvim-qt.exe"

function wtd { wt -d . }

# touch
function touch ($command) {
    New-Item -Path $command -ItemType File | out-null && Write-Host Created $command
}

function rm ($command) {
    Remove-Item $command -Recurse && Write-Host Removed $command
}

## $Env:PATH management
Function Add-DirectoryToPath {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias("FullName")]
        [string] $path,
        [string] $variable = "PATH",

        [switch] $clear,
        [switch] $force,
        [switch] $prepend,
        [switch] $whatIf
    )

    BEGIN {

        ## normalize paths

        $count = 0
        $paths = @()

        if (-not $clear.IsPresent) {

            $environ = Invoke-Expression "`$Env:$variable"
            $environ.Split(";") | ForEach-Object {
                if ($_.Length -gt 0) {
                    $count = $count + 1
                    $paths += $_.ToLowerInvariant()
                }
            }

            Write-Verbose "Currently $($count) entries in `$env:$variable"
        }

        Function Array-Contains {
            param(
                [string[]] $array,
                [string] $item
            )

            $any = $array | Where-Object -FilterScript {
                $_ -eq $item
            }

            Write-Output ($null -ne $any)
        }
    }

    PROCESS {

        if ([IO.Directory]::Exists($path) -or $force.IsPresent) {

            $path = $path.Trim()

            $newPath = $path.ToLowerInvariant()
            if (-not (Array-Contains -Array $paths -Item $newPath)) {
                if ($whatIf.IsPresent) {
                    Write-Host $path
                }

                if ($prepend.IsPresent) { $paths = , $path + $paths }
                else { $paths += $path }

                Write-Verbose "Adding $($path) to `$env:$variable"
            }
        }
        else {

            Write-Host "Invalid entry in `$Env:$($variable): ``$path``" -ForegroundColor Yellow

        }
    }

    END {

        ## re-create PATH environment variable

        $separator = [IO.Path]::PathSeparator
        $joinedPaths = [string]::Join($separator, $paths)

        if ($whatIf.IsPresent) {
            Write-Output $joinedPaths
        }
        else {
            Invoke-Expression " `$env:$variable = `"$joinedPaths`" "
        }
    }

}

. oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\amro.omp.json" | Invoke-Expression

Import-Module Terminal-Icons

Set-PSReadLineOption -BellStyle None

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

function ll {
    Get-ChildItem $Args[0] |
        Format-Table Mode, @{N='Owner';E={(Get-Acl $_.FullName).Owner}}, Length, LastWriteTime, @{N='Name';E={if($_.Target) {$_.Name+' -> '+$_.Target} else {$_.Name}}}
}

function whereis ($command) {
    Get-Command -Name $command -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}

function reloadprofile {
    @(
        $Profile.AllUsersAllHosts,
        $Profile.AllUsersCurrentHost,
        $Profile.CurrentUserAllHosts,
        $Profile.CurrentUserCurrentHost
    ) | % {
        if(Test-Path $_){
            Write-Verbose "Running $_"
            . $_
        }
    }
}
zadjii-msft commented 2 months ago

So, I can't see the scrollbar in that video, but my psychic debugging is telling me that you're still in alternate scroll mode for some reason. That's a special mode where mouse wheels send up and down keystrokes instead of mouse wheel events. But it's only supposed to be active when in the "alternate screen buffer" (which is used by full screen apps like vim).

You could probably check that easily on your side by seeing if there's a scrollbar enabled in the "main" buffer after exiting nvim

radiaku commented 2 months ago

Hello @zadjii-msft , I think this is true. I still cant replicate that, if not long run on nvim.

Btw if in case I still on alternate scroll mode after exiting nvim. can

How I can exit ( disable ) it? maybe adding some function on $profile ?? or any function that help?

Update: Yeah true the scrollbar is not showing

https://github.com/user-attachments/assets/bc841ba1-972a-44ee-8dd4-1ca0171c1e1a

j4james commented 2 months ago

@radiaku If you're using PowerShell, you should be able to get the terminal to return to the main buffer by entering this at the prompt:

"`e[?1049l"

Once you're back in the main buffer the scrollbar should appear again, and the mouse wheel should work as you expect.

radiaku commented 2 months ago

@j4james , Thanks for your help. its working like a charm.

For short I create this function on $PROFILE and call cas for short.

function cas {
  # Clear Alternate Screen
  # https://github.com/microsoft/terminal/issues/17739
  [System.Console]::Write("`e[?1049l")
}

I leave this one on here if anybody need this.