Skip to content

diff: count -t columns like a terminal after CR, backspace and controls - #384

Open
binhvq wants to merge 3 commits into
uutils:mainfrom
binhvq:expand-tabs-control-chars
Open

binhvq wants to merge 3 commits into
uutils:mainfrom
binhvq:expand-tabs-control-chars

Conversation

@binhvq

@binhvq binhvq commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #354.

do_expand_tabs measured the Unicode width of everything between tabs, so control characters threw the padding off. It now tracks the column like GNU diff 3.12 does with -t:

  • \r goes back to column 0. In the normal and context formats the line marker (< , ! , ...) is written again after it when more text follows; unified and ed don't repeat theirs, same as GNU.
  • \b goes one column back. At column 0 it is dropped, which is also what GNU prints.
  • other control characters, C1 included, take no column
  • invalid UTF-8 bytes take one column each, instead of the whole chunk being counted by bytes when one byte is invalid

Text runs between control characters are still measured with UnicodeWidthStr, so the ZWJ emoji test keeps its width. do_write_line takes the marker as a new argument.

Checked against GNU diff in en_US.UTF-8 for the normal, unified, context and ed formats. In the C locale GNU counts every non-ASCII byte as one column; that was already different here and isn't touched.

@github-actions

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 20 / FAILED: 9 / SKIPPED: 4
  Reference: TOTAL: 33 / PASSED: 19 / FAILED: 10 / SKIPPED: 4

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + expand-tabs

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.

diff - -t tab expansion miscounts columns after CR, backspace and control bytes

1 participant