"less" pager renders in the wrong color when started at the bottom of the screen from powershell #4487

Open
opened 2026-01-30 23:48:57 +00:00 by claunia · 9 comments
Owner

Originally created by @jeffrson on GitHub (Oct 16, 2019).

Environment

Windows build number: 10.0.18362.356
Windows Terminal version (if applicable): 0.5.2762.0

Any other software? less pager (https://chocolatey.org/packages/Less)

Steps to reproduce

Open PowerShell Tab
less <somefile> will show the file in foreground color
gci
less <somefile> will show the file in black color

Expected behavior

<somefile> should be shown in foreground color

Actual behavior

Somehow, after "gci" the file is shown in black. This does not happen with Cmd (note: at least when I tried to reproduce it, but I believe it had happened previously with cmd as well) and it doesn't happen in PowerShell or Cmd standalone (same note applies).

Originally created by @jeffrson on GitHub (Oct 16, 2019). # Environment ```none Windows build number: 10.0.18362.356 Windows Terminal version (if applicable): 0.5.2762.0 Any other software? less pager (https://chocolatey.org/packages/Less) ``` # Steps to reproduce Open PowerShell Tab `less <somefile>` will show the file in foreground color `gci` `less <somefile>` will show the file in black color # Expected behavior `<somefile>` should be shown in foreground color # Actual behavior Somehow, after "gci" the file is shown in black. This does not happen with Cmd (note: at least when I tried to reproduce it, but I believe it had happened previously with cmd as well) and it doesn't happen in PowerShell or Cmd standalone (same note applies).
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 16, 2019):

This doesn't happen when you just use powershell directly (not inside Windows Terminal,) right?

@DHowett-MSFT commented on GitHub (Oct 16, 2019): This doesn't happen when you just use powershell directly (not inside Windows Terminal,) right?
Author
Owner

@jeffrson commented on GitHub (Oct 16, 2019):

Yes, indeed.

@jeffrson commented on GitHub (Oct 16, 2019): Yes, indeed.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 21, 2019):

This is likely some combination of #2661 and #293.

@DHowett-MSFT commented on GitHub (Oct 21, 2019): This is likely some combination of #2661 and #293.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 24, 2019):

It's a little bit more insidious than that. It looks like less is reading the color of the cell under the cursor when it's launched and using that as the default text color. Now, as for why it's getting 0x00 (black on black) from that cell in Windows Terminal where it's not in the legacy Console Host... that's a very good question.

@DHowett-MSFT commented on GitHub (Oct 24, 2019): It's a little bit more insidious than that. It looks like `less` is reading the color of the cell under the cursor when it's launched and using that as the default text color. Now, as for why it's getting `0x00` (black on black) from that cell in Windows Terminal where it's not in the legacy Console Host... that's a very good question.
Author
Owner

@jeffrson commented on GitHub (Oct 24, 2019):

Thanks for investigating!

It may be related to Powershell. With cmd the bug doesn't occur. However, when I run powershell from this cmd, call gci (which is important, otherwise it seems to work) subsequent calls to less show letters in black again. Even after exiting from this instance of PowerShell! Maybe it's something that gci does? Edit: you're right - it's not gci, it occurs after output reaches the bottom of the screen somehow - nevertheless it does this only in PowerShell for me. And it does not return, even after the screen is cleared.

What's strange now: PowerShell 7 Preview 5 (did not test with 4) shows the same behaviour - outside Windows Terminal (in its own Conhost or whatever).

@jeffrson commented on GitHub (Oct 24, 2019): Thanks for investigating! It may be related to Powershell. With cmd the bug doesn't occur. However, when I run `powershell` from this cmd, call `gci` (which is important, otherwise it seems to work) subsequent calls to less show letters in black again. Even after exiting from this instance of PowerShell! Maybe it's something that `gci` does? Edit: you're right - it's not gci, it occurs after output reaches the bottom of the screen somehow - nevertheless it does this only in PowerShell for me. And it does not return, even after the screen is cleared. What's strange now: PowerShell 7 Preview 5 (did not test with 4) shows the same behaviour - *outside* Windows Terminal (in its own Conhost or whatever).
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 29, 2019):

Yanking the triage tag off this. It's interesting that the cell less is reading is different inside/outside of terminal and with powershell core 6/7/windows powershell 5.

@DHowett-MSFT commented on GitHub (Oct 29, 2019): Yanking the triage tag off this. It's interesting that the cell _less_ is reading is different inside/outside of terminal and with powershell core 6/7/windows powershell 5.
Author
Owner

@xa0082249956 commented on GitHub (Nov 1, 2019):

Issue maybe releated to this one:
Output is invisible when run under PowerShell Core #10

More Details I Found:
The color is rendered correctly if I pressing Ctrl+L before using less.
And then problem occurs if I typing on the bottom line of the Terminal (In either Windows PowerShell or PowerShell Core, by hitting enter until I can type on the bottom).

@xa0082249956 commented on GitHub (Nov 1, 2019): Issue maybe releated to this one: [Output is invisible when run under PowerShell Core #10](https://github.com/gwsw/less/issues/10) **More Details I Found**: The color is **rendered correctly** if I pressing `Ctrl`+`L` before using `less`. And then **problem occurs** if I typing on the bottom line of the Terminal (In either Windows PowerShell or PowerShell Core, by hitting `enter` until I can type on the bottom).
Author
Owner

@jpetkau commented on GitHub (Nov 8, 2019):

It may be related to Powershell. With cmd the bug doesn't occur. However, when I run powershell

I'm seeing this issue in cmd, using the less.exe from UnxUtils.

The bug happens any time after the either the cursor has been at the bottom of the screen, or the screen has been cleared (cls). The only time it doesn't happen is when I'm in a new terminal window and haven't yet scrolled or cleared it.

Using Terminal 0.6.2951.0, less.exe from http://unxutils.sourceforge.net/.

It notice it doesn't happen on my laptop. I looked for differences between them, and determined that it's due to my prompt:

PROMPT=$_$E[m$E[32m[ $D $T %COMPUTERNAME%$E\$S$E[92m$P $E[32m]$E[90m$_$E[90m$G$E[m

(Just started using Terminal and hadn't got around to configuring the prompt on my laptop yet.)

If I change the prompt to avoid reset ($E[m) and always explicitly set a color instead, I don't see the bug:

PROMPT=$_$E[32m[ $D $T %COMPUTERNAME%$E\$S$E[92m$P $E[32m]$E[90m$_$E[90m$G$E[37m
@jpetkau commented on GitHub (Nov 8, 2019): > It may be related to Powershell. With cmd the bug doesn't occur. However, when I run `powershell` I'm seeing this issue in cmd, using the `less.exe` from UnxUtils. The bug happens any time after the either the cursor has been at the bottom of the screen, or the screen has been cleared (`cls`). The only time it doesn't happen is when I'm in a new terminal window and haven't yet scrolled or cleared it. Using Terminal 0.6.2951.0, `less.exe` from http://unxutils.sourceforge.net/. It notice it doesn't happen on my laptop. I looked for differences between them, and determined that it's due to my prompt: PROMPT=$_$E[m$E[32m[ $D $T %COMPUTERNAME%$E\$S$E[92m$P $E[32m]$E[90m$_$E[90m$G$E[m (Just started using Terminal and hadn't got around to configuring the prompt on my laptop yet.) If I change the prompt to avoid reset (`$E[m`) and always explicitly set a color instead, I don't see the bug: PROMPT=$_$E[32m[ $D $T %COMPUTERNAME%$E\$S$E[92m$P $E[32m]$E[90m$_$E[90m$G$E[37m
Author
Owner

@jredfox commented on GitHub (May 25, 2022):

Capture
confirmed this issue. the issue is being caused by powershell itself most likely. if you do start-process "java" -ArgumentList '-jar', '"C:\Users\jredfox\Desktop\Apps\launcher-1.09_ 15.jar"' it will open up a black window in conhost instead of a blue window. running powershell it will be blue from the shortcut but using the exe directly will cause it to happen again. reproducable with both conhost.exe and windows terminal

but in this case we use this command wt -p "Windows PowerShell" and the output is a black screen instead of blue

@jredfox commented on GitHub (May 25, 2022): ![Capture](https://user-images.githubusercontent.com/9736369/170195945-9343a214-e4e6-477f-a06d-64f80a6efeec.PNG) confirmed this issue. the issue is being caused by powershell itself most likely. if you do ` start-process "java" -ArgumentList '-jar', '"C:\Users\jredfox\Desktop\Apps\launcher-1.09_ 15.jar"'` it will open up a black window in conhost instead of a blue window. running powershell it will be blue from the shortcut but using the exe directly will cause it to happen again. reproducable with both conhost.exe and windows terminal but in this case we use this command `wt -p "Windows PowerShell"` and the output is a black screen instead of blue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4487