Skip to content

Conversation

@clipperhouse
Copy link
Owner

@clipperhouse clipperhouse commented Dec 14, 2025

TruncateString|Bytes is intended to truncate a string to a maximum display width, including the width of an optional tail (like an ellipsis, e.g.).


Note

Introduces truncation by display width with optional tails and validates performance/behavior across libraries.

  • Adds Options.TruncateString, TruncateString, Options.TruncateBytes, and TruncateBytes in width.go (grapheme-aware; tail width accounted)
  • Extensive tests: new cases in width_test.go, cross-lib comparisons in comparison/behavior_test.go, and fuzzing (FuzzTruncateStringAndBytes); strengthens FuzzBytesAndString
  • Benchmarks: adds BenchmarkTruncateWithTail and BenchmarkTruncateWithoutTail in comparison/benchmark_test.go; updates benchmark outputs in README.md and comparison/README.md
  • Documentation/notes: updates compatibility analysis (flags discussion) and README references
  • Misc: add *.out to .gitignore

Written by Cursor Bugbot for commit dd91ee1. Configure here.

@clipperhouse
Copy link
Owner Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@clipperhouse clipperhouse marked this pull request as ready for review January 11, 2026 17:46
Copilot AI review requested due to automatic review settings January 11, 2026 17:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds string and byte slice truncation methods that are grapheme-aware and account for display width, including support for optional tail strings (e.g., ellipsis).

Changes:

  • Adds TruncateString and TruncateBytes functions with Options variants for grapheme-aware truncation by display width
  • Comprehensive test suite including unit tests, fuzz tests, cross-library comparison tests, and benchmarks
  • Updated documentation including README benchmark results and compatibility analysis notes

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
width.go Implements core truncation logic for strings and bytes with grapheme boundary handling
width_test.go Extensive test cases covering edge cases, wide characters, emoji, and grapheme sequences
fuzz_test.go Adds fuzzing for truncate functions and strengthens existing fuzz tests
comparison/benchmark_test.go Benchmarks truncation performance with and without tails against go-runewidth
comparison/behavior_test.go Cross-library behavioral comparison tests for truncation
comparison/README.md Updated benchmark results including new truncation benchmarks
README.md Updated benchmark results including new truncation benchmarks
comparison/COMPATIBILITY_ANALYSIS.md Adds discussion about flag width handling in different terminals
.gitignore Adds *.out pattern for Go test output files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@clipperhouse clipperhouse merged commit 433ade9 into main Jan 11, 2026
10 checks passed
@clipperhouse clipperhouse deleted the truncate branch January 11, 2026 18:26
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