Paragraph borders messed up when I resize the terminal

Hello,

I’ve been learning Ratatui and started with a simple gps visualization app. The issue I am having is that when I resize the terminal the borders don’t seem to redraw correctly. I’m sure I’m doing somthing silly but cannot figure out quite whats is wrong.

The NEMA messages are used to build up a vector of Lines that’s handed to a Paragraph. It looks fine until I resize. I’ve tried with scrollbar and wrap on and off.

*note: I blacked out the actual lat/lon on the GLL message, the issue is with the borders so please ignore that.

Thanks,

Jeff

Are there ANSI codes or special characters embedded in the text. I suspect a tab character is likely the culprit.

If so, filter those chars out of the text before rendering (replace a tab with some amount of spaces).

If not, see if you can create a minimal repro (delete all the code that’s not a problem and hard code some values to show off what’s happening).

I believe that’s it. I was using from_utf8_lossy on the raw nema messages which contains \r\n and then a bunch of \0’s. So I assume it was either the \r\n or the \0 getting turned into �.

I stripped all that off and it appears to work. Still not sure why it was fine until I resized terminal though? Anyways thanks for your help.

Still not sure why it was fine until I resized terminal though?

I suspect that this caused a weird interaction with the double buffering and the way the diff works. First rendered frame renders correctly because we treat the characters as 0 width, but render them regardless. Second render only rendering changed characters, but having the \r\n somewhere in the line causes the line rendering to skip to the next while rendering. There’s some code which fixes the next position to render at, which doesn’t account for tabs, newlines, and ANSI codes which don’t have simple sizes that they would move the cursor.

There’s a partially related issue at Can't render tab character with Paragraph. · Issue #876 · ratatui/ratatui · GitHub (and it’s on my list of things which should be fixed at some point more generally - I’ll add a proper issue to capture it soon).

1 Like