Pager icon indicating copy to clipboard operation
Pager copied to clipboard

Dynamic help pager breaks scrolling in original view buffer

Open heaths opened this issue 3 years ago • 8 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues, especially the pinned issues.

Exception report

N/A

Screenshot

This shows the interactions. Where my mouse isn't moving, I'm using my mouse wheel to scroll up and down.

https://user-images.githubusercontent.com/1532486/151895211-967ecf33-86fc-43c2-9eb5-31dc5446a395.mp4

Environment data

PS Version: 7.2.1
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.2.1-rc1
PSReadLine EditMode: Windows
OS: 10.0.22000.1 (WinBuild.160101.0800)
BufferWidth: 148
BufferHeight: 48

Steps to reproduce

  1. Run a command that causes a scrollbar in your terminal e.g., Windows Terminal. Like dir -recurse $env:TEMP.
  2. Confirm that you can scroll up and down with your mouse, scrollbar, etc.
  3. Run dir and press F1.
  4. Press Q to quit.
  5. Try to scroll like you did for step 2.

Expected behavior

I can scroll up and down as before.

Actual behavior

No scrolling or scrollbar. There also appear to be scrollbar-like buttons in the main buffer that do nothing. It's almost as if the main buffer was clear except for the current view port, an alternate buffer was created, then destroyed to show the original but only the displayed buffer was restored.

FWIW, I can create an alternate buffer, write to it, and restore the original via ANSI sequences without this behavior:

&{
  write-host "`e[?1049hHello, world!"
  sleep -seconds 1
  write-host "`e[?1049l"
}

Even with this little script, I noticed that the main scroll buffer was not modified. Seems perhaps the main buffer is modified before using a alternate buffer, or maybe no alternate buffer is used (which was mentioned in release notes for dynamic help) - at least, not using ANSI sequences.

heaths avatar Feb 01 '22 01:02 heaths

I believe Windows Terminal deliberately tells the console that its view buffer is much smaller vertically than the scrollback buffer that Windows Terminal itself actually maintains for the user. It is odd, though, that use of the pager apparently causes WT to clear its own scrollback buffer.

@dhowett might be able to offer some insight here, but it sounds like we might need to implement a fix for WT specifically (or maybe it's an edge case bug in WT?).

vexx32 avatar Feb 02 '22 13:02 vexx32

Yes, WT does report 1 column less to avoid wrapping issues like with conhost. Perhaps that explains the pager scroll buttons left behind, but I would expect that sending "`e[1049l" to clear the alternate buffer would clear the entirety of the buffer, or does the pager actually set its own extents?

heaths avatar Feb 02 '22 19:02 heaths

I use the same escape sequence of entering the alternate buffer and exiting it. I would need to debug why it does not work with the pager specifically.

adityapatwardhan avatar Feb 04 '22 00:02 adityapatwardhan

Just found the issue. The only difference between your example and what pager does is it uses [Console]::ReadKey($true) to intercept the key input. When this is added to the example it, repros the issue.

&{
  write-host "`e[?1049hHello, world!"  
  $x = [Console]::ReadKey($true)
  write-host "`e[?1049l"
}

adityapatwardhan avatar Feb 04 '22 00:02 adityapatwardhan

Odd. Perhaps a bug in Terminal, @DHowett? Though, I would think a bug intercepting keys in an alternate buffer would've surfaced long before now.

heaths avatar Feb 07 '22 20:02 heaths

I was about to file a bug on Windows Terminal, but cannot repro it anymore. My current Windows terminal version is:

Windows Terminal Version: 1.12.10334.0

@heaths can you see if you can still repro?

adityapatwardhan avatar Feb 08 '22 15:02 adityapatwardhan

Yep, still repros for me on WT 1.12.10334.0 whether I simply press "q" once the pager starts, or down and/or up buttons to scroll first before pressing "q".

Of interest, I installed PSReadLine 2.2.1-rc1 into my Ubuntu 18.04 WSL2 environment (also running pwsh 7.2.1), restarted pwsh, and this scenario works i.e., the scrollbar behavior is what I would expect even when the pager is visible:

image

You can see the scrollbar and the history buffer hasn't been cleared. If I press "q" the scrollbar appears no different, and I can scroll up/down the screen buffer just fine.

heaths avatar Feb 08 '22 18:02 heaths

Perhaps it has something to do with https://github.com/PowerShell/Pager/blob/965675f549dfa074eb02a47ca6d6e07d0ee7771f/src/IConsole.cs#L100 ? How about clearing it with the VT clear command ?

This doesn't reproduce in

&{
  write-host "`e[?1049hHello, world!"  
  $x = [Console]::ReadKey($true)
  write-host "`e[?1049l"
}
# scrollback still works

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> get-module PSReadline

ModuleType Version    PreRelease Name                                
---------- -------    ---------- ----                                
Script     2.2.5                 PSReadLine                          

> Get-PSReadLineOption

EditMode                               : Windows
AddToHistoryHandler                    : System.Func`2[System.String,System.Object]
HistoryNoDuplicates                    : True
HistorySaveStyle                       : SaveIncrementally
HistorySearchCaseSensitive             : False
HistorySearchCursorMovesToEnd          : True
MaximumHistoryCount                    : 4096
ContinuationPrompt                     : >>
ExtraPromptLineCount                   : 1
PromptText                             :
BellStyle                              : Audible
DingDuration                           : 50
DingTone                               : 1221
CommandsToValidateScriptBlockArguments : {ForEach-Object, %, Invoke-Command, icm…}
CommandValidationHandler               :
CompletionQueryItems                   : 100
MaximumKillRingCount                   : 10
ShowToolTips                           : True
ViModeIndicator                        : None
WordDelimiters                         : ;:,.[]{}()/\|^&*-=+'"–—―
AnsiEscapeTimeout                      : 100
PredictionSource                       : HistoryAndPlugin
PredictionViewStyle                    : ListView

Luiz-Monad avatar Jun 10 '22 18:06 Luiz-Monad