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

fix: incorrect line skipping in renderer flush #1233

Merged
merged 5 commits into from
Nov 12, 2024

Conversation

semihbkgr
Copy link
Contributor

fixes #1232

To fix the bug described in the issue, we can simply store the currently rendered lines and use them for comparison in the upcoming flush operation.

@semihbkgr
Copy link
Contributor Author

@meowgorithm
Copy link
Member

Totally, this is a regression. Appreciate all the work and insight on this one, @semihbkgr; we’re checking this out now.

Copy link
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with the provided example and everything seems to work as expected.

@semihbkgr Could you please add comments in the code explaining why you're doing this? I know you explained this in the issue, but it would be more beneficial to have some explanation in the code 🙂

@LeperGnome
Copy link
Contributor

I could reproduce the bug, yea

@meowgorithm
Copy link
Member

@LeperGnome and does this patch fix it for you?

@LeperGnome
Copy link
Contributor

LeperGnome commented Nov 12, 2024

@meowgorithm I found out that this bug was present in the original renderer before 1.2.0, but in a slightly different form... I'm tinkering around, still can't really wrap my head around it. I managed to fix it myself by:

	r.lastRender = strings.Join(newLines, "\n") // instead of r.buf.String()

But I didn't test current patch yet.

EDIT:
current patch fixed the example from the related issue, but I didn't test anything beyond that.

@LeperGnome
Copy link
Contributor

Yea, as @semihbkgr pointed out in #1232 it seems like the issue lies in the fact, that lastRender contains all the lines (even not rendered) from the previous frame, and newLines are being trimmed to fit the window height. So at the end, we don't match lines correctly to see if they're the same. ouch

@LeperGnome
Copy link
Contributor

Oh, wait.. @aymanbagabas did you reproduce the bug or not? I might've misunderstood your comment

@aymanbagabas
Copy link
Member

@LeperGnome Yes, I was able to reproduce the bug. This patch fixes the issue

@@ -34,6 +34,7 @@ type standardRenderer struct {
ticker *time.Ticker
done chan struct{}
lastRender string
lastRenderedLines []string
linesRendered int
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can possibly remove the linesRendered field and use len(lastRenderedLines) instead. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will break tea.Println. We reset the lastRenderedLines when we call repaint, which is the case when using tea.Println. We need to keep track of the number of lines last rendered for tea.Println to work.

@aymanbagabas aymanbagabas merged commit 97fc4fa into charmbracelet:main Nov 12, 2024
22 checks passed
@LeperGnome
Copy link
Contributor

As a side note - maybe it's a good thing to introduce tests for such corner-cases? I'll definitely help when working on new renderer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect line skipping in renderer flush
4 participants