Word wrap counts color code as characters #7

Open
opened 2018-09-23 06:18:02 +00:00 by freemo · 0 comments
freemo commented 2018-09-23 06:18:02 +00:00 (Migrated from git.qoto.org)

Metadata

  • Commit Message: fix(display): exclude color codes from word wrap character count
  • Branch: bugfix/m2-word-wrap-color

Background and Context

The word wrap algorithm in lib/aethyr/core/render/text_util.rb (or format.rb) counts ANSI color escape sequences as visible characters. This causes lines to wrap prematurely — the wrap point is calculated as if the invisible escape bytes were printable, resulting in lines that are shorter than the terminal width.

Current Behavior

A line containing color codes wraps at fewer visible characters than expected. For example, a line that should wrap at 80 visible characters may wrap at 60 if it contains 20 characters worth of escape sequences.

Expected Behavior

The word wrap algorithm strips or ignores ANSI escape sequences when calculating line width. The wrap point is determined by visible character count only. Color codes are preserved in the output but do not affect wrap calculations.

Acceptance Criteria

  • Word wrap calculates line width based on visible characters only (ANSI escapes excluded)
  • Color codes are preserved across word wrap boundaries (color state is maintained)
  • Lines wrap at the correct visible column regardless of color code density
  • No visual artifacts from split color sequences at wrap points

Subtasks

  • Code: Identify the word wrap function in lib/aethyr/core/render/ (likely text_util.rb or format.rb)
  • Code: Modify the width calculation to strip ANSI escape sequences (regex: /\e\[[0-9;]*m/) before measuring line length
  • Code: Ensure color state is tracked across wrap boundaries — if a line is split mid-color, re-emit the active color code at the start of the next line
  • Code: Handle edge cases: nested color codes, reset sequences, lines that are entirely color codes
  • Docs: Update YARD comments on the word wrap function
  • Tests (Cucumber): Add tests/unit/word_wrap_color.feature covering: plain text wrapping (baseline), colored text wrapping at correct column, color state preservation across wrap, deeply nested colors
  • Tests (Cucumber Integration): Add integration feature verifying word-wrapped colored output displays correctly in a connected client.
  • Tests (Profiling): Run bundle exec rake unit_profile and verify no performance regressions.
  • Quality: Verify coverage >=97% via bundle exec rake unit. If coverage is <97% then review the current unit test coverage report at build/tests/unit/coverage/ and use it to write new Cucumber based unit tests to improve code coverage. Specifically, write Cucumber/Gherkin style unit tests that are descriptively named and specifically improve coverage on whichever file has the most uncovered lines by writing tests that will target the uncovered lines in the report. Once that is done rerun bundle exec rake unit to verify all tests pass and coverage is above >=97%. Only mark this as complete once coverage is >=97%, if not repeat this task as many times as is needed until coverage reaches >=97%.
  • Quality: Run bundle exec rake (default task: unit tests with coverage) and bundle exec rake integration, fix any errors if needed ensuring both pass across entire code base, do not ignore any failure even if it seems unrelated to this commit, fix it.

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
## Metadata - **Commit Message**: `fix(display): exclude color codes from word wrap character count` - **Branch**: `bugfix/m2-word-wrap-color` ## Background and Context The word wrap algorithm in `lib/aethyr/core/render/text_util.rb` (or `format.rb`) counts ANSI color escape sequences as visible characters. This causes lines to wrap prematurely — the wrap point is calculated as if the invisible escape bytes were printable, resulting in lines that are shorter than the terminal width. ## Current Behavior A line containing color codes wraps at fewer visible characters than expected. For example, a line that should wrap at 80 visible characters may wrap at 60 if it contains 20 characters worth of escape sequences. ## Expected Behavior The word wrap algorithm strips or ignores ANSI escape sequences when calculating line width. The wrap point is determined by visible character count only. Color codes are preserved in the output but do not affect wrap calculations. ## Acceptance Criteria - [ ] Word wrap calculates line width based on visible characters only (ANSI escapes excluded) - [ ] Color codes are preserved across word wrap boundaries (color state is maintained) - [ ] Lines wrap at the correct visible column regardless of color code density - [ ] No visual artifacts from split color sequences at wrap points ## Subtasks - [ ] Code: Identify the word wrap function in `lib/aethyr/core/render/` (likely `text_util.rb` or `format.rb`) - [ ] Code: Modify the width calculation to strip ANSI escape sequences (regex: `/\e\[[0-9;]*m/`) before measuring line length - [ ] Code: Ensure color state is tracked across wrap boundaries — if a line is split mid-color, re-emit the active color code at the start of the next line - [ ] Code: Handle edge cases: nested color codes, reset sequences, lines that are entirely color codes - [ ] Docs: Update YARD comments on the word wrap function - [ ] Tests (Cucumber): Add `tests/unit/word_wrap_color.feature` covering: plain text wrapping (baseline), colored text wrapping at correct column, color state preservation across wrap, deeply nested colors - [ ] Tests (Cucumber Integration): Add integration feature verifying word-wrapped colored output displays correctly in a connected client. - [ ] Tests (Profiling): Run `bundle exec rake unit_profile` and verify no performance regressions. - [ ] Quality: Verify coverage >=97% via `bundle exec rake unit`. If coverage is <97% then review the current unit test coverage report at `build/tests/unit/coverage/` and use it to write new Cucumber based unit tests to improve code coverage. Specifically, write Cucumber/Gherkin style unit tests that are descriptively named and specifically improve coverage on whichever file has the most uncovered lines by writing tests that will target the uncovered lines in the report. Once that is done rerun `bundle exec rake unit` to verify all tests pass and coverage is above >=97%. Only mark this as complete once coverage is >=97%, if not repeat this task as many times as is needed until coverage reaches >=97%. - [ ] Quality: Run `bundle exec rake` (default task: unit tests with coverage) and `bundle exec rake integration`, fix any errors if needed ensuring both pass across **entire** code base, do not ignore any failure even if it seems unrelated to this commit, fix it. ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done.
freemo self-assigned this 2026-03-15 04:25:21 +00:00
freemo added this to the (deleted) milestone 2026-03-15 04:25:48 +00:00
freemo modified the milestone from (deleted) to v1.1.0 2026-03-16 00:28:16 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference: aethyr/Aethyr#7
No description provided.