Skip to content

Commit

Permalink
Print tail before resetting ANSI when truncating
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm authored and muesli committed May 2, 2021
1 parent db37f10 commit c80126e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion truncate/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ func (w *Writer) Write(b []byte) (int, error) {
}

if curWidth > w.width {
n, err := w.buf.WriteString(w.tail)
if w.ansiWriter.LastSequence() != "" {
w.ansiWriter.ResetAnsi()
}
return w.buf.WriteString(w.tail)
return n, err
}

_, err := w.ansiWriter.Write([]byte(string(c)))
Expand Down
7 changes: 7 additions & 0 deletions truncate/truncate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func TestTruncate(t *testing.T) {
"\x1B[7m--",
"\x1B[7m--",
},
// Tail is printed before reset sequence:
{
3,
"…",
"\x1B[38;5;219mHiya!",
"\x1B[38;5;219mHi…\x1B[0m",
},
}

for i, tc := range tt {
Expand Down

0 comments on commit c80126e

Please sign in to comment.