Skip to content

Commit

Permalink
fix(term): ansi: truncate being stuck on incorrect uniseg state
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Mar 14, 2024
1 parent 7e3a0e0 commit 1028789
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions exp/term/ansi/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func Truncate(s string, length int, tail string) string {
buf.WriteByte(r)
}

gstate = -1 // reset grapheme state otherwise, width calculation might be off
// Done collecting, now we're back in the ground state.
pstate = GroundState
continue
Expand Down
1 change: 1 addition & 0 deletions exp/term/ansi/truncate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var tcases = []struct {
{"unicode", "\x1b[35mClaire‘s Boutique\x1b[0m", "", 8, "\x1b[35mClaire‘s\x1b[0m"},
{"wide_chars", "こんにちは", "…", 7, "こんに…"},
{"style_wide_chars", "\x1b[35mこんにちは\x1b[m", "…", 7, "\x1b[35mこんに…\x1b[m"},
{"osc8_lf", "สวัสดีสวัสดี\x1b]8;;https://example.com\x1b\\\nสวัสดีสวัสดี\x1b]8;;\x1b\\", "…", 9, "สวัสดีสวัสดี\x1b]8;;https://example.com\x1b\\\n\x1b]8;;\x1b\\"},
}

func TestTruncate(t *testing.T) {
Expand Down

0 comments on commit 1028789

Please sign in to comment.