Skip to content

Commit 99b85ff

Browse files
committed
fix: renderer: erase the rest of the line when it's shorter than the 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)
1 parent f4d1e0e commit 99b85ff

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

standard_renderer.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,15 @@ func (r *standardRenderer) flush() {
190190
if flushQueuedMessages {
191191
// Dump the lines we've queued up for printing.
192192
for _, line := range r.queuedMessageLines {
193-
// Removing previousy rendered content at the end of line.
194-
line = line + ansi.EraseLineRight
193+
if ansi.StringWidth(line) < r.width {
194+
// We only erase the rest of the line when the line is shorter than
195+
// the width of the terminal. When the cursor reaches the end of
196+
// the line, any escape sequences that follow will only affect the
197+
// last cell of the line.
198+
199+
// Removing previously rendered content at the end of line.
200+
line = line + ansi.EraseLineRight
201+
}
195202

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

222229
line := newLines[i]
223230

224-
// Removing previousy rendered content at the end of line.
225-
line = line + ansi.EraseLineRight
226-
227231
// Truncate lines wider than the width of the window to avoid
228232
// wrapping, which will mess up rendering. If we don't have the
229233
// width of the window this will be ignored.
@@ -235,6 +239,16 @@ func (r *standardRenderer) flush() {
235239
line = ansi.Truncate(line, r.width, "")
236240
}
237241

242+
if ansi.StringWidth(line) < r.width {
243+
// We only erase the rest of the line when the line is shorter than
244+
// the width of the terminal. When the cursor reaches the end of
245+
// the line, any escape sequences that follow will only affect the
246+
// last cell of the line.
247+
248+
// Removing previously rendered content at the end of line.
249+
line = line + ansi.EraseLineRight
250+
}
251+
238252
_, _ = buf.WriteString(line)
239253

240254
if i < len(newLines)-1 {

0 commit comments

Comments
 (0)