Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line drawing artefacts in Tree on Windows, in Windows Terminal #2548

Closed
davep opened this issue May 11, 2023 · 18 comments · Fixed by #3644
Closed

Line drawing artefacts in Tree on Windows, in Windows Terminal #2548

davep opened this issue May 11, 2023 · 18 comments · Fixed by #3644
Assignees
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented May 11, 2023

To start with I'm adding this as a tentative bug report, as I doubt it's really a Tree or DirectoryTree issue, but I have never seen it before and only noticed it while testing the work done on #2545; it's very likely going to require some attempts at isolation.

Simply put, while playing with a sandbox application to soak-test the worker-updating of DirectoryTree on Windows, depending on terminal size, sometimes I'd see artefacts like this:

Screenshot 2023-05-11 at 15 09 31

Presumably the old "multibyte character got truncated" issue. Unsurprisingly it would then throw off the rest of the line it was on:

Screenshot 2023-05-11 at 15 10 37

Here's the whole terminal, putting it in context (see the bottom row):

Screenshot 2023-05-11 at 14 02 32

However... in this particular case, the issue would only show up if focus was within the first six director trees (the first two rows). If I tabbed focus into any of the final three it would fix itself:

Screenshot 2023-05-11 at 14 02 56 Screenshot 2023-05-11 at 14 03 09 Screenshot 2023-05-11 at 14 03 20

As mentioned above, this did seem to change the way it worked depending on the size of the terminal, and the content; but I didn't really spend too much time trying to narrow that down as I was trying to concentrate on the thing I was in Windows to test.

I've not been able to recreate the issue on macOS.

Like I say: this is placed here for further investigation, and hopefully to take a bit of time to try and come up with a way to replicate the problem in as minimal an example as possible.

@davep davep added bug Something isn't working Task labels May 11, 2023
@davep
Copy link
Contributor Author

davep commented May 17, 2023

Update: not just line drawing characters. Still only seeing this in Windows Terminal. This particular glitch only happened when the focus was on the same row.

Screenshot 2023-05-17 at 13 31 09 Screenshot 2023-05-17 at 13 31 20

@denisrossetre
Copy link

I've got the same problem on Windows as well.

@davep
Copy link
Contributor Author

davep commented Oct 11, 2023

@willmcgugan Looking back to find this issue again and this very much looks to be the same thing we were looking at at my desk just now, with the key tester/recorder app under Windows (both Terminal and Hyper). The behaviour I recorded above, with the directory tree, displayed all the same symptoms and had the same feel in regards to the possible underlying cause (multibyte character at the end of a buffer sort of thing).

@davep
Copy link
Contributor Author

davep commented Oct 30, 2023

Moving this into todo. I feel this is important enough that it go into the queue of things getting attention soon; even if it's to narrow down the cause.

@TomJGooding
Copy link
Contributor

TomJGooding commented Oct 30, 2023

@davep This behaviour is a bit unpredictable, but from playing around with this I think I've discovered that weirdly this seems to go away when the padding setting in Windows Terminal is set to zero...

@davep
Copy link
Contributor Author

davep commented Oct 30, 2023

Interesting. The working hypothesis was that it was a buffer size issue on our side (either in Textual or Python). Hadn't considered it would be a Windows Terminal issue.

It'll be interesting to try and reproduce the issue in Tabby, Wez or Hyper, etc. What you say suggests it should not happen.

@TomJGooding
Copy link
Contributor

TomJGooding commented Oct 30, 2023

I might be wrong as the behaviour is a bit unpredictable. But interestingly, it looks like the problem also goes away if you set the padding to the same size as the font.

Edit: Nope, looks I can reproduce on Wezterm after minimising then maximizing the window, so this must just be pure coincidence, sorry.

image

@davep
Copy link
Contributor Author

davep commented Oct 30, 2023

No apologies needed. All useful stuff for eliminating the possible causes and influences.

@TomJGooding
Copy link
Contributor

While messing around with resizing the Windows Terminal, I found you also can create other strange displays like below. The other screenshots show missing glyhs, whereas here it looks like the bottom corner of the border has been duplicated.

image

@davep davep self-assigned this Nov 7, 2023
@davep
Copy link
Contributor Author

davep commented Nov 7, 2023

Trying to make a small tool that will hopefully allow me to get a stable reproduction of this issue and... so far so good. One thing I've found is that, given a particular terminal size (I've not tried other sizes yet, that's next), I can get corruption to appear at the exact same spot, every single time:

Screenshot 2023-11-07 at 11 31 27

If I close the app down, run it up again, the corruption appears in the same place, starting around character 1504. The second location is always 3584.

@davep
Copy link
Contributor Author

davep commented Nov 7, 2023

Different terminal sizes have the corruption at different locations, but always in the same location every time. There is a pattern. Likewise, if i make a fresh terminal the same size as the one above, I see the exact same pattern.

@darrenburns
Copy link
Member

🍿

@davep
Copy link
Contributor Author

davep commented Nov 7, 2023

Using the same test application, I've recreated the problem, with very similar results, using:

  • Hyper
  • Wez
  • Tabby

I did try rio too but, while I've managed to install it, I can't seem to get it running to the point that I get a prompt. I think it's fair to assume though that the issue will be evident there also. This would very much suggest that the problem is either within Textual itself, or something in the Windows build of Python.

davep added a commit to davep/textual that referenced this issue Nov 7, 2023
This is experimental. I think, ideally, we'll do this by finding an optimal
buffer size and writing based on that, but for the moment let's just try
line-by-line as that's easy.

This will be used to test against the tool I've made that lets me recreate
the issue documented in Textualize#2548; if this does the job we'll take this further.
@davep
Copy link
Contributor Author

davep commented Nov 7, 2023

Quick experiment with davep@357268e and it seems to be solving the issue.

davep added a commit to davep/textual that referenced this issue Nov 7, 2023
First we tested this by splitting the output by lines; that worked but it
could be faster. So now we're going to take the problematic buffer
size (32KiB), assume a reasonable worst case of every character heading out
being 3 bytes in size, and chunking the output based on that.

In other words, experiment for Textualize#2548 take two.
@davep
Copy link
Contributor Author

davep commented Nov 7, 2023

Seems to be down to python/cpython#82052 so fix is incoming which will chunk up the writes when on Windows.

Copy link

github-actions bot commented Nov 7, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@darrenburns
Copy link
Member

Oof, nice work! 👏

@davep
Copy link
Contributor Author

davep commented Nov 7, 2023

To be clear: this was a known issue, and was what was suspected to start off with (see initial details), and this is applying a version of a workaround that's already in Rich. So I can't take credit for the fix, just perhaps for being double-sure that the problem was the problem. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants