Skip to content

Adopt 8-bit ANSI option#22

Merged
clipperhouse merged 7 commits intomainfrom
contrl-sequences-8-bit
Feb 17, 2026
Merged

Adopt 8-bit ANSI option#22
clipperhouse merged 7 commits intomainfrom
contrl-sequences-8-bit

Conversation

@clipperhouse
Copy link
Owner

@clipperhouse clipperhouse commented Feb 16, 2026

uax29 added an option for 8-bit control sequences. This PR adds support for that option in width calculations.

It turns out that Truncate with 8-bit escapes can lead to confusing outcomes, by concatenating bytes that, when combined, form a new UTF-8 codepoint. That’s bad. This was discovered by fuzzing. I’ve decided to have Truncate only respect the 7-bit option (which was the status quo). Better for the package to have a limitation than confusion.

Copilot AI review requested due to automatic review settings February 16, 2026 17:35
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 support for 8-bit ECMA-48 control sequences by introducing a new ControlSequences8Bit option. This complements the existing ControlSequences option (which handles 7-bit sequences) and leverages the recently added 8-bit control sequence support in the uax29 v2.7.0 library.

Changes:

  • Added ControlSequences8Bit field to the Options struct to enable zero-width treatment of 8-bit C1 control sequences (0x80-0x9F)
  • Updated width calculation logic to treat graphemes starting with C1 control bytes as zero-width when the option is enabled
  • Enhanced truncate functions to preserve both 7-bit and 8-bit trailing escape sequences based on the respective options
  • Added comprehensive test coverage for 8-bit sequences, independence of 7-bit/8-bit options, and mixed scenarios
  • Created separate options.go file to consolidate option definitions (refactoring)
  • Created separate truncate.go file for truncation functions (refactoring)

Reviewed changes

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

Show a summary per file
File Description
options.go New file containing the Options struct with the new ControlSequences8Bit field and DefaultOptions
width.go Added C1 control byte detection for zero-width treatment; removed Options definition and truncate functions (moved to separate files)
truncate.go New file containing truncation functions; updated to handle both 7-bit and 8-bit escape sequences with the new isEscapeLeader helper
graphemes.go Updated to configure the grapheme iterator with AnsiEscapeSequences8Bit option
width_test.go Added comprehensive tests for 8-bit sequences, independence tests, and regression test for truncation edge case
fuzz_test.go Added 8-bit control sequences to fuzz test seeds and option combinations

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

@clipperhouse clipperhouse merged commit 77f9fe2 into main Feb 17, 2026
10 checks passed
@clipperhouse clipperhouse deleted the contrl-sequences-8-bit branch February 17, 2026 03:05
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