Skip to content

Conversation

@clipperhouse
Copy link
Owner

When a string is truncated and includes escape sequences, the string may be left “open ended”, i.e. the later reset code will not be there, and in a terminal this would therefore affect all following text. Like any other markup, really.

This PR changes Truncate* to scan the string filling the truncation point, collecting the subsequent escape code, and appending them. They won’t be visible, but they will offer “closure” of earlier sequences.

This PR does not evaluate the escape, only identifies and includes.

Also rename IgnoreControlSequencesControlSequences. We’re not ignoring them, per se, rather it’s a new mode that does different things.

Copilot AI review requested due to automatic review settings February 8, 2026 23:00
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 PR improves terminal-safety of truncated strings by preserving ANSI/ECMA-48 escape sequences that occur after the truncation point (to avoid “open-ended” styling like color bleed), and renames the option controlling escape-sequence handling from IgnoreControlSequences to ControlSequences.

Changes:

  • Update TruncateString/TruncateBytes to append subsequent ANSI escape sequences after truncation when Options.ControlSequences is enabled.
  • Rename Options.IgnoreControlSequencesOptions.ControlSequences across code, tests, docs, and fuzzing.
  • Add benchmarks for truncation performance with/without escape-sequence preservation.

Reviewed changes

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

Show a summary per file
File Description
width.go Renames option; updates truncation logic to preserve trailing escape sequences; updates method docs.
width_test.go Updates tests to new option name and adds truncation expectations including preserved trailing sequences.
graphemes.go Wires Options.ControlSequences into the uax29 grapheme iterator.
fuzz_test.go Updates fuzz option matrices and invariants for renamed field.
truncate_bench_test.go Adds microbenchmarks for truncate behavior with ANSI-heavy inputs.
README.md Updates public documentation for the renamed option.
CHANGELOG.md Updates release notes for the renamed option and new truncation behavior.
.gitignore Ignores *.test artifacts.

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

@clipperhouse clipperhouse merged commit 154f35a into main Feb 9, 2026
10 checks passed
@clipperhouse clipperhouse deleted the ansi-truncate branch February 9, 2026 01:07
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.

1 participant