Skip to content

text: make RepeatAndTrim handle escape sequences and display width - #454

Merged
jedib0t merged 1 commit into
mainfrom
text-repeat-and-trim
Nov 12, 2026
Merged

jedib0t merged 1 commit into
mainfrom
text-repeat-and-trim

Conversation

@jedib0t

@jedib0t jedib0t commented Nov 12, 2026

Copy link
Copy Markdown
Owner
  • measure the string in display columns instead of runes
  • use the escape sequences found around the text once, around the repeated text, instead of counting them as text
  • return an empty string for a negative width instead of panicking
  • skip the trim when whole copies fill the width exactly
  • let Trim take box drawing, Latin, Greek and Cyrillic characters as grapheme clusters of their own, the way it takes ASCII and CJK
  • add a benchmark for RepeatAndTrim
Benchmark Before After
RepeatAndTrim, ASCII 90 12
RepeatAndTrim, box drawing 1024 34
RepeatAndTrim, escaped 234 85
Table_Render 9293 7652
Table_RenderLarge 2,021,179 2,052,288

- measure the string in display columns instead of runes
- use the escape sequences found around the text once, around the repeated
  text, instead of counting them as text
- return an empty string for a negative width instead of panicking
- skip the trim when whole copies fill the width exactly
- let Trim take box drawing, Latin, Greek and Cyrillic characters as
  grapheme clusters of their own, the way it takes ASCII and CJK
- add a benchmark for RepeatAndTrim
@sonarqubecloud

Copy link
Copy Markdown

@jedib0t
jedib0t merged commit cfdcca3 into main Nov 12, 2026
4 checks passed
@jedib0t
jedib0t deleted the text-repeat-and-trim branch November 12, 2026 22:27
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 43319784887

Coverage remained the same at 99.927%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 42 of 42 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 5493
Covered Lines: 5489
Line Coverage: 99.93%
Coverage Strength: 1.21 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants