Skip to content

feat: add colorized option for highstate output#68982

Open
mdschmitt wants to merge 2 commits into
saltstack:masterfrom
mdschmitt:colorized_diff_output
Open

feat: add colorized option for highstate output#68982
mdschmitt wants to merge 2 commits into
saltstack:masterfrom
mdschmitt:colorized_diff_output

Conversation

@mdschmitt

@mdschmitt mdschmitt commented Apr 22, 2026

Copy link
Copy Markdown

What does this PR do?

Adds optional colorization for diff chunks in the highstate output module.

disclaimer: I used AI to assist me in creating and testing this code, but it works appropriately as far as I can tell. The original version I had wasn't nearly as clean and smooth as this ended up.

I had some trouble getting all the pre-commit hooks to play nice on my Fedora laptop but I'm fairly sure that a workflow run will succeed. I'll obviously make changes if that's not the case.

What issues does this PR fix or reference?

I didn't submit an issue for this; I did however mention it a while back in Discord.
This is me attempting to upstream the polished final result.

Previous Behavior

All diff output in highstate output module was green regardless of additions/deletions

New Behavior

If specified, the full_color, changes_color and such output modes will show a colorized diff in the state return output (such as for file.managed). The results are colorized like so:

  • Added lines are green
  • Removed lines are red
  • Hunk headers are cyan
  • Surrounding context lines are standard white/gray.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No, but signed with ssh key (so it looks like GitHub itself re-signed it with gpg key ID B5690EEEBB952194)

@mdschmitt mdschmitt requested a review from a team as a code owner April 22, 2026 11:17
@mdschmitt mdschmitt force-pushed the colorized_diff_output branch 2 times, most recently from 10dc1af to a45beb9 Compare April 23, 2026 07:00
Colorize unified diffs in the highstate outputter: added lines are green, removed lines are red, hunk headers are cyan, and context lines are gray.
`newfile:` and other change keys are rendered with the same indentation as the current functionality provides.
@dwoz dwoz force-pushed the colorized_diff_output branch from a45beb9 to 8dea3a0 Compare June 12, 2026 23:44
@dwoz dwoz added the test:full Run the full test suite label Jun 12, 2026
@dwoz dwoz added this to the Potassium v3009.0 milestone Jun 13, 2026
- Black reformat the lines.extend() generator call in _render_changes_dict
- Replace U+2192 arrows in _render_diff docstring with ASCII -> so the
  cp1252 docstring-encoding hook passes (these characters break salt-run -d
  and salt -d on Windows where stdout uses the locale-default encoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants