Skip to content
Myr

fix: renderer: erase the rest of the line when it's shorter than the width

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Ayman Bagabas · committed by Ayman Bagabas · parent f4d1e0e · Browse files · 1 file+19 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fixes: https://github.com/charmbracelet/bubbletea/issues/1225
  • Fixes: 0cef3c7896a8 (feat(render): remove flickering)

Diff stats

1 file+19 added−5 removed

  • other:+19 added−5 removed

1 file+19 added−5 removed

modified:standard_renderer.go+19 added-5 removed
188 unmodified lines
189190 if flushQueuedMessages {191 // Dump the lines we've queued up for printing.192 for _, line := range r.queuedMessageLines {193 // Removing previousy rendered content at the end of line.194 line = line + ansi.EraseLineRight193 if ansi.StringWidth(line) < r.width {194 // We only erase the rest of the line when the line is shorter than195 // the width of the terminal. When the cursor reaches the end of196 // the line, any escape sequences that follow will only affect the197 // last cell of the line.198199 // Removing previously rendered content at the end of line.200 line = line + ansi.EraseLineRight201 }202203 _, _ = buf.WriteString(line)204 _, _ = buf.WriteString("\r\n")205 }206 // Clear the queued message lines.
20 unmodified lines
227 }228229 line := newLines[i]230224 // Removing previousy rendered content at the end of line.225 line = line + ansi.EraseLineRight226231 // Truncate lines wider than the width of the window to avoid232 // wrapping, which will mess up rendering. If we don't have the233 // width of the window this will be ignored.234 //
3 unmodified lines
238 if r.width > 0 {239 line = ansi.Truncate(line, r.width, "")240 }241242 if ansi.StringWidth(line) < r.width {243 // We only erase the rest of the line when the line is shorter than244 // the width of the terminal. When the cursor reaches the end of245 // the line, any escape sequences that follow will only affect the246 // last cell of the line.247248 // Removing previously rendered content at the end of line.249 line = line + ansi.EraseLineRight250 }251252 _, _ = buf.WriteString(line)253254 if i < len(newLines)-1 {255 _, _ = buf.WriteString("\r\n")
507 unmodified lines