Skip to content

Commit

Permalink
fix: renderer: erase the rest of the line when it's shorter than the …
Browse files Browse the repository at this point in the history
…width

When the cursor reaches the end of the line, any escape sequences that
follow will only affect the last cell of the line. This is why we only
erase the rest of the line when the line is shorter than the width of
the terminal.

Fixes: #1225
Fixes: 0cef3c7 (feat(render): remove flickering)
  • Loading branch information
aymanbagabas committed Nov 8, 2024
1 parent f4d1e0e commit 99b85ff
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,15 @@ func (r *standardRenderer) flush() {
if flushQueuedMessages {
// Dump the lines we've queued up for printing.
for _, line := range r.queuedMessageLines {
// Removing previousy rendered content at the end of line.
line = line + ansi.EraseLineRight
if ansi.StringWidth(line) < r.width {
// We only erase the rest of the line when the line is shorter than
// the width of the terminal. When the cursor reaches the end of
// the line, any escape sequences that follow will only affect the
// last cell of the line.

// Removing previously rendered content at the end of line.
line = line + ansi.EraseLineRight
}

_, _ = buf.WriteString(line)
_, _ = buf.WriteString("\r\n")
Expand Down Expand Up @@ -221,9 +228,6 @@ func (r *standardRenderer) flush() {

line := newLines[i]

// Removing previousy rendered content at the end of line.
line = line + ansi.EraseLineRight

// Truncate lines wider than the width of the window to avoid
// wrapping, which will mess up rendering. If we don't have the
// width of the window this will be ignored.
Expand All @@ -235,6 +239,16 @@ func (r *standardRenderer) flush() {
line = ansi.Truncate(line, r.width, "")
}

if ansi.StringWidth(line) < r.width {
// We only erase the rest of the line when the line is shorter than
// the width of the terminal. When the cursor reaches the end of
// the line, any escape sequences that follow will only affect the
// last cell of the line.

// Removing previously rendered content at the end of line.
line = line + ansi.EraseLineRight
}

_, _ = buf.WriteString(line)

if i < len(newLines)-1 {
Expand Down

0 comments on commit 99b85ff

Please sign in to comment.