Skip to content

Conversation

@kpengboy
Copy link
Contributor

This would at least be a partial solution to #371.

I did not add the colorization to the cfgtest output, but I wonder if I should.

@codecov
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 15.15152% with 28 lines in your changes missing coverage. Please review.

Project coverage is 37.72%. Comparing base (0739f1f) to head (299fa73).

Files with missing lines Patch % Lines
cmd/gmailctl/cmd/apply_cmd.go 0.00% 8 Missing ⚠️
cmd/gmailctl/cmd/diff_cmd.go 0.00% 7 Missing ⚠️
cmd/gmailctl/cmd/edit_cmd.go 0.00% 7 Missing ⚠️
internal/engine/apply/apply.go 0.00% 3 Missing ⚠️
internal/engine/label/diff.go 0.00% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (15.15%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
- Coverage   37.81%   37.72%   -0.10%     
==========================================
  Files          53       53              
  Lines        4458     4472      +14     
==========================================
+ Hits         1686     1687       +1     
- Misses       2685     2698      +13     
  Partials       87       87              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2025

This pull request is stale because it has been open for 30 days without activity.
This will be closed in 7 days, unless you add the 'lifecycle/keep-alive' label or comment.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. label Mar 2, 2025
@kpengboy
Copy link
Contributor Author

kpengboy commented Mar 9, 2025

keepalive

@github-actions github-actions bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. label Mar 10, 2025
@kpengboy kpengboy force-pushed the color-diffs branch 2 times, most recently from e724ff2 to 8180c28 Compare April 25, 2025 08:16
Copy link
Owner

@mbrt mbrt left a comment

Choose a reason for hiding this comment

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

Nice, thanks! I can't immediately see why, but I tested manually, and it looks like gmailctl diff --color=never still colorizes the output. Could you double-check? Maybe I'm missing something.

@kpengboy
Copy link
Contributor Author

kpengboy commented May 8, 2025

Sorry about that. I fixed it so label diffs respect --color too.

Also, would you want a --color=always option to be implemented? If so we would have to implement the colorization logic ourselves instead of using the martinohmann difflib fork, but it doesn't seem very complicated to do

@mbrt
Copy link
Owner

mbrt commented May 12, 2025

@kpengboy I think this looks good enough, thanks!
Could you please rebase, resolve the conflicts and fix the tests? After that we can merge

@kpengboy
Copy link
Contributor Author

Rebased.

@mbrt
Copy link
Owner

mbrt commented May 21, 2025

Could you please fix the tests?

@kpengboy
Copy link
Contributor Author

Fixed the tests. Also, I wrote an alternative version of this PR which supports --color=always by implementing the diff colorization logic in-application (which was not too complex) rather than using the martinohmann library. This is the code for it: master...kpengboy:gmailctl:color-diffs-2. If you'd also prefer that, we could use that branch instead of this PR.

@mbrt
Copy link
Owner

mbrt commented Jun 18, 2025

@kpengboy I think it's fine to move to the slightly newer (but still unmaintained) version from martinhomann. I'm also fine if you prefer to move the implementation of the colorization detection to inside here. I checked the branch and it looks pretty simple.

Just one comment on the branch:

I would prefer to keep the reporting package agnostic of flags. This means that the only functions exported would be: ColorizeDiff and IsTerminalColorized that just returns true when the terminal supports coloring.

The logic of parsing the --color flag and deciding what to do can be delegated to a function in cmd/gmailctl/cmd/io.go. This way you can also hardcode the name of the flag in the error message and don't have to pass it around. This keeps a clear separation of concerns, as flags logic never leaves the cmd packages.

I hope this makes sense.

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for 30 days without activity.
This will be closed in 7 days, unless you add the 'lifecycle/keep-alive' label or comment.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. label Jul 19, 2025
@mbrt
Copy link
Owner

mbrt commented Jul 20, 2025

keep alive

@mbrt mbrt removed the lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. label Jul 20, 2025
@kpengboy kpengboy force-pushed the color-diffs branch 2 times, most recently from 562b789 to e6fec45 Compare July 21, 2025 13:16
@kpengboy
Copy link
Contributor Author

I've chosen to move to the alternative implementation. I moved the shouldUseColorDiff function from the reporting package to the cmd package too. PTAL

@kpengboy kpengboy changed the title Switch to martinohmann difflib fork and colorize diff output Colorize diff output Jul 22, 2025
Copy link
Owner

@mbrt mbrt left a comment

Choose a reason for hiding this comment

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

Nice work! Just a minor nit

Whether to colorize the diff output is controlled by a --color flag.
@mbrt
Copy link
Owner

mbrt commented Aug 16, 2025

Nice job! Thanks @kpengboy!

@mbrt mbrt merged commit e9bd182 into mbrt:master Aug 16, 2025
3 checks passed
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.

2 participants