terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Reflow behavior on window resize seems broken if the cursor is hidden

Open kunom opened this issue 9 months ago • 3 comments

Windows Terminal version

1.19.10821.0

Windows build number

10.0.19045.4291

Other Software

No response

Steps to reproduce

I have a strange reflow bug that seems to occur only when the cursor is hidden. Steps to reproduce:

  1. Paste the following Python code into a file named status.py:
    import time
    
    HIDE_CURSOR = "\x1b[?25l"
    LF_AND_CLEAR_LINE = "\r\x1b[2K"
    
    print("foo " * 100)
    print()
    print(HIDE_CURSOR)  # --> removing this line fixes the issue
    for i in range(100000):
        print(f"{LF_AND_CLEAR_LINE}working {i}...", end="", flush=True)
        time.sleep(0.05)
    
  2. Start the script in a new, non-maximized window: start status.py
  3. Take your mouse and rapidly change the width of the window, so that content is repeatedly reflowed. See heavy display distortions: image
  4. In the script, remove the "hide cursor" statement and redo the test. Everything works fine now, regardless how heavy you try to distort the display: image

Expected Behavior

The reflow mechanism should work regardless of whether the cursor is rendered or not. The behaviour with the visible cursor is the correct one.

Actual Behavior

It looks as if the display reflow logic is broken when the cursor is not rendered, maybe the full line inclusive trailing whitespace is reflowed?

kunom avatar Apr 28 '24 14:04 kunom

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Apr 28 '24 14:04 github-actions[bot]

Version Repro?
1.20.10822
1.19.10821
1.18.3181 ✅, but not as badly

Looks like this script doesn't enable VIRTUAL_TERMINAL_PROCESSING mode before printing control sequences. This isn't the root cause but it will cause problems down the line.

carlos-zamora avatar May 01 '24 21:05 carlos-zamora

My example script is a stripped-down version of using the rich package, which seems to be widely adopted and is even referenced by the pip module.

import rich.status
import time

with rich.status.Status("working..."):
    time.sleep(10000)

rich somehow cares about ENABLE_VIRTUAL_TERMINAL_PROCESSING and the console mode, but only queries it and never calls SetConsoleMode().

What sort of issues do you have in mind when talking about "problems down the line"?

kunom avatar May 02 '24 06:05 kunom

Same issue with a much more complicated example:

Cursor shown and resizing no issue

https://github.com/microsoft/terminal/assets/53280662/1d3792a3-cfe3-48a2-bc07-c8c17e98917e

Cursor hidden and artifacts when resizing

https://github.com/microsoft/terminal/assets/53280662/fb6b47d3-a26f-4616-aea4-1f01092d6401

salt-die avatar Jul 05 '24 16:07 salt-die

I tested this with #17510 and at least the initial 2 repros above seem to be fixed.

lhecker avatar Jul 05 '24 16:07 lhecker