Skip to content

Add --no-unicode flag to disable combining marks in output - #105

Open
pbottine wants to merge 1 commit into
masterfrom
add-no-unicode-flag
Open

Add --no-unicode flag to disable combining marks in output#105
pbottine wants to merge 1 commit into
masterfrom
add-no-unicode-flag

Conversation

@pbottine

Copy link
Copy Markdown

This commit adds a new command-line flag --no-unicode that allows users to disable Unicode combining marks (strikethrough and underline characters) in the diff output while preserving ANSI color highlighting. This addresses the issue where the dual formatting (colors + unicode marks) creates difficulties when converting output to HTML and LaTeX formats.

The implementation:

  • Adds --no-unicode flag to the argument parser in main.py
  • Passes the enable_unicode parameter to the Printer constructor
  • Sets the CombiningMarkWriter.enabled property based on user preference

When --no-unicode is specified, only ANSI colors are used to highlight additions (green) and deletions (red), making the output easier to process downstream while maintaining visual differentiation.

Fixes #35

🤖 Generated with Claude Code

This commit adds a new command-line flag `--no-unicode` that allows users
to disable Unicode combining marks (strikethrough and underline characters)
in the diff output while preserving ANSI color highlighting. This addresses
the issue where the dual formatting (colors + unicode marks) creates
difficulties when converting output to HTML and LaTeX formats.

The implementation:
- Adds `--no-unicode` flag to the argument parser in __main__.py
- Passes the `enable_unicode` parameter to the Printer constructor
- Sets the `CombiningMarkWriter.enabled` property based on user preference

When `--no-unicode` is specified, only ANSI colors are used to highlight
additions (green) and deletions (red), making the output easier to process
downstream while maintaining visual differentiation.

Fixes #35

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@pbottine
pbottine requested a review from ESultanik as a code owner November 24, 2025 19:57
@pbottine

Copy link
Copy Markdown
Author

cc: @smoelius

@ESultanik

Copy link
Copy Markdown
Collaborator

This PR doesn't seem to disable combining markers in unicode output, it disables all output, if I am reading the code changes correctly. I need to test it a bit more to confirm.

@ESultanik ESultanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the patch, and apologies for leaving this sitting for so long.

First, correcting my earlier comment. I said this looked like it disabled all output rather than only the combining marks. I have now tested it, and that reading was wrong. CombiningMarkWriter.write reads enabled only to choose between interleaving marks and a plain raw_write, and the same text reaches the stream either way. The flag does what its help text says.

Your patch was blocked by a separate bug, which is now fixed on master. When I tested this branch, redirected output came out with neither colors nor marks, which made the diff unreadable. That turned out not to be your change: colorama.init() was running at import time and replacing sys.stdout with a wrapper that strips ANSI whenever stdout is not a terminal. Forcing --color into a file produced zero escape bytes on master too, with or without your patch. I filed that as #128 and fixed it in #130.

Could you merge in master or rebase onto master? After that, these are the remaining items:

  1. Add a test. test/test_graphtage.py already builds Printer(ansi_color=True, out_stream=StringIO()) and asserts on exact output, so a case that prints the same diff with enable_unicode=False and asserts the result equals the marked output with U+0336 and U+031F removed fits in a few lines.
  2. Consider an HTMLPrinter.under_plus() override to match the strike() override at printer.py:639. Under --html --color --no-unicode, removals keep their text-decoration: line-through span while insertions lose their marker.
  3. Consider noting in the --help text that the flag applies only when color is on. With --no-color, @only_ansi (printer.py:401-417) already suppresses the marks and you get the ++/~~ fallbacks, so --no-color --no-unicode and --no-color produce identical output. I measured both at 89 bytes.

Item 1 is the one I would like before merging. Items 2 and 3 are optional and I am happy to take them as follow-ups.

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.

Option to remove the plusses from the output?

2 participants