Missing lines in the output when using with PowerShell #7880

Closed
opened 2026-01-31 01:14:54 +00:00 by claunia · 7 comments
Owner

Originally created by @Vlad-Shcherbina on GitHub (May 2, 2020).

Environment

Windows build number: Microsoft Windows NT 10.0.18363.0
Windows Terminal version (if applicable):  0.11.1191.0

Any other software?

Powershell:
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      18362  752

CPython, version irrelevant. Doesn't even have to be Python,
it's just what I happened to use in the repro steps below.

Steps to reproduce

  1. Create the following Python program:
    for i in range(30):
        print('*' * 20)
        print('-' * 20)
    
  2. Open Windows PowerShell tab.
  3. Run this program: python hello.py
  4. Run this program again: python hello.py
  5. Scroll up using mouse wheel.

Expected behavior

PS C:\temp> python hello.py
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
PS C:\temp> python hello.py
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
PS C:\temp>

Actual behavior

PS C:\temp> python hello.py
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
PS C:\temp> python hello.py
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
********************
--------------------
PS C:\temp>
Originally created by @Vlad-Shcherbina on GitHub (May 2, 2020). # Environment ```none Windows build number: Microsoft Windows NT 10.0.18363.0 Windows Terminal version (if applicable): 0.11.1191.0 Any other software? Powershell: Major Minor Build Revision ----- ----- ----- -------- 5 1 18362 752 CPython, version irrelevant. Doesn't even have to be Python, it's just what I happened to use in the repro steps below. ``` # Steps to reproduce 1. Create the following Python program: ```python for i in range(30): print('*' * 20) print('-' * 20) ``` 2. Open Windows PowerShell tab. 3. Run this program: `python hello.py` 4. Run this program again: `python hello.py` 5. Scroll up using mouse wheel. # Expected behavior ``` PS C:\temp> python hello.py ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- PS C:\temp> python hello.py ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- PS C:\temp> ``` # Actual behavior ``` PS C:\temp> python hello.py ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- PS C:\temp> python hello.py ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- ******************** -------------------- PS C:\temp> ```
claunia added the Resolution-ExternalNeeds-Tag-Fix labels 2026-01-31 01:14:54 +00:00
Author
Owner

@Vlad-Shcherbina commented on GitHub (May 2, 2020):

This happens on Terminal Preview + PowerShell, but not on Terminal Preview + cmd or on standard Windows terminal + PowerShell.

It's not just a rendering glitch. When the output is copied to the clipboard, it still misses a line.

When trying it with a window of a different height, a different line is missing.

@Vlad-Shcherbina commented on GitHub (May 2, 2020): This happens on Terminal Preview + PowerShell, but not on Terminal Preview + cmd or on standard Windows terminal + PowerShell. It's not just a rendering glitch. When the output is copied to the clipboard, it still misses a line. When trying it with a window of a different height, a different line is missing.
Author
Owner

@jdhitsolutions commented on GitHub (May 2, 2020):

I see similar results running the PowerShell equivalent of the Python script.

1..30 | foreach { write "$_ $("*"*20)";Write ("-"*20)}

The first time I run the command I can scroll up and see results as expected. But when I run it a second time and scroll up to the first results I'm missing a line. When running in PowerShell 7 it is even worse as sometimes I'm missing half the of the previous output. But that may be a quirk when running Clear-Host.

I get similar results with a shorter number of iterations like 15.

I also tested with a command like Get-Process. I ran the command, then copied and pasted the results into the PowerShell ISE to make it easy to see line numbers. I had 300 lines. Then I ran Get-Process again and scrolled up to the previous result to again copy and paste. Now I only get 299 lines. This is in line with the other testing.

@jdhitsolutions commented on GitHub (May 2, 2020): I see similar results running the PowerShell equivalent of the Python script. ```powershell 1..30 | foreach { write "$_ $("*"*20)";Write ("-"*20)} ``` The first time I run the command I can scroll up and see results as expected. But when I run it a second time and scroll up to the first results I'm missing a line. When running in PowerShell 7 it is even worse as sometimes I'm missing half the of the previous output. But that may be a quirk when running Clear-Host. I get similar results with a shorter number of iterations like 15. I also tested with a command like Get-Process. I ran the command, then copied and pasted the results into the PowerShell ISE to make it easy to see line numbers. I had 300 lines. Then I ran Get-Process again and scrolled up to the previous result to again copy and paste. Now I only get 299 lines. This is in line with the other testing.
Author
Owner

@DHowett-MSFT commented on GitHub (May 2, 2020):

This sounds weirdly like this old PSReadline issue where it was telling us to “scroll the screen” instead of “insert a new line” before it displayed the prompt ...

If you just hold down Enter at your powershell prompt, does it stop putting your prompt into the scrollback at some point?

https://github.com/PowerShell/PSReadLine/issues/724

@DHowett-MSFT commented on GitHub (May 2, 2020): This sounds weirdly like this old PSReadline issue where it was telling us to “scroll the screen” instead of “insert a new line” before it displayed the prompt ... If you just hold down Enter at your powershell prompt, does it stop putting your prompt into the scrollback at some point? https://github.com/PowerShell/PSReadLine/issues/724
Author
Owner

@Vlad-Shcherbina commented on GitHub (May 2, 2020):

@DHowett-MSFT , if I keep pressing Enter in a fresh PowerShell tab, the prompt appears every time. But the output buffer stops growing once it occupies exactly one screen and the prompt is at the very bottom. So there is never a scroll bar. Few more presses make the initial PowerShell message disappear. Past this point, every time I press Enter, nothing on screen changes but for a small redraw flicker. I don't know if it's because one of the old lines disappears, or because the new prompt doesn't appear.

@Vlad-Shcherbina commented on GitHub (May 2, 2020): @DHowett-MSFT , if I keep pressing Enter in a fresh PowerShell tab, the prompt appears every time. But the output buffer stops growing once it occupies exactly one screen and the prompt is at the very bottom. So there is never a scroll bar. Few more presses make the initial PowerShell message disappear. Past this point, every time I press Enter, nothing on screen changes but for a small redraw flicker. I don't know if it's because one of the old lines disappears, or because the new prompt doesn't appear.
Author
Owner

@DHowett-MSFT commented on GitHub (May 3, 2020):

So, alright, this one is a somewhat sad story.

Past this point, every time I press Enter, nothing on screen changes but for a small redraw flicker.

Yep. PowerShell that comes with Windows ships with a version of PSReadline that's frozen in time. It was built somewhere between 2.0.0-beta2 and 2.0.0-beta3. Unfortunately, that means it doesn't have the fix for PowerShell/PSReadline#724.

NOTE: it's hard to tell, because Get-Module PSReadline will not tell you the beta number! It will report 2.0.0 every time.

Because it doesn't have the fix for PSReadline 724, when it prints a new line at the bottom of the screen, it tells the whole console to "shift your contents up by one line". This means that the console window Terminal is talking to needs to redraw 100% of the content on the screen, because it doesn't currently support the "scroll" operation (that's another can of worms 😄).

It moves to the top line, and overwrites it with the line below it . . . and then does that until it gets to the bottom line, which it erases.

The top line is destroyed instead of being placed into the scrollback.

If PSReadline just emitted a newline character, the topmost line would be pushed up into the scrollback, and the new bottom line would be naturally created blank with the appropriate attributes.

This is fixed in PowerShell 6+ and 7.

Because the inbox Windows PowerShell is stuck at 5.1, with an outdated version of PSReadline, this may never get fixed -- but there isn't too much that Terminal can do about it. It happens in VSCode and WSL as well, for the same reason.

@zadjii-msft: is this something that we could shim? Now that we've cracked that cask of ale open, I want to drink from it all the time 😉
Or, if we supported ConPTY passing through scroll events, ... this might magically start working again.

For now, resolving External.

@DHowett-MSFT commented on GitHub (May 3, 2020): So, alright, this one is a somewhat sad story. > Past this point, every time I press Enter, nothing on screen changes but for a small redraw flicker. Yep. PowerShell that comes with Windows ships with a version of PSReadline that's frozen in time. It was built somewhere between 2.0.0-beta2 and 2.0.0-beta3. Unfortunately, that means it _doesn't_ have the fix for PowerShell/PSReadline#724. _NOTE: it's hard to tell, because `Get-Module PSReadline` will _not_ tell you the beta number! It will report `2.0.0` every time._ Because it doesn't have the fix for PSReadline 724, when it prints a new line at the bottom of the screen, it tells the _whole console_ to "shift your contents up by one line". This means that the console window Terminal is talking to needs to redraw 100% of the content on the screen, because it doesn't currently support the "scroll" operation (that's another can of worms :smile:). It moves to the top line, and overwrites it with the line below it . . . and then does that until it gets to the bottom line, which it erases. The top line is destroyed instead of being placed into the scrollback. If PSReadline just emitted a newline character, the topmost line would be pushed up into the scrollback, and the new bottom line would be naturally created blank with the appropriate attributes. **This is fixed in PowerShell 6+ and 7.** Because the inbox Windows PowerShell is stuck at 5.1, with an outdated version of PSReadline, this may never get fixed -- but there isn't too much that Terminal can do about it. It happens in VSCode and WSL as well, for the same reason. @zadjii-msft: is this something that we could shim? Now that we've cracked that cask of ale open, I want to drink from it all the time :wink: Or, if we supported ConPTY passing through scroll events, ... this might magically start working again. For now, resolving External.
Author
Owner

@Vlad-Shcherbina commented on GitHub (May 3, 2020):

@DHowett-MSFT , if old PowerShell and Windows are to blame, why doesn't this happen when old PowerShell is used in the standard Windows terminal instead of Terminal Preview?

@Vlad-Shcherbina commented on GitHub (May 3, 2020): @DHowett-MSFT , if old PowerShell and Windows are to blame, why doesn't this happen when old PowerShell is used in the standard Windows terminal instead of Terminal Preview?
Author
Owner

@woojoo666 commented on GitHub (Nov 29, 2021):

in case anybody else got here and was a little confused by the "this may never get fixed" statement made earlier, @DHowett-MSFT is talking about Powershell 5.1. You can still install Powershell 7, but note that it will co-exist alongside Powershell 5.1. So you will have to set Windows Terminal to use Powershell 7 by default if you don't want to worry about the missing lines issue ever again.

@woojoo666 commented on GitHub (Nov 29, 2021): in case anybody else got here and was a little confused by the "this may never get fixed" statement made earlier, @DHowett-MSFT is talking about Powershell 5.1. You can still install [Powershell 7](https://docs.microsoft.com/en-us/powershell/scripting/whats-new/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7.2), but note that it will co-exist alongside Powershell 5.1. So you will have to set Windows Terminal to use Powershell 7 by default if you don't want to worry about the missing lines issue ever again.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7880