Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --color cli switch #320

Merged
merged 3 commits into from Jul 17, 2022
Merged

Conversation

mjpieters
Copy link
Contributor

This adds a --color switch to the pueue command, controlling when output will
include ANSI styles (colors, bolding). The default, auto matches the current
behaviour: style when connected to a TTY.

This PR refactors the way styling is handled (consolidating color choices and
styling into a single location struct), and this struct then tracks if styling
can be output or not.

This would fix #318.

Checklist

  • I picked the correct source and target branch.
  • I included a new entry to the CHANGELOG.md.
  • I checked cargo clippy and cargo fmt. The CI will fail otherwise anyway.
  • (If applicable) I added tests for this feature or adjusted existing tests.
  • (If applicable) I checked if anything in the wiki needs to be changed.

@mjpieters mjpieters force-pushed the cli-color-option branch 2 times, most recently from ac0ad03 to fbc5187 Compare July 4, 2022 16:09
@mjpieters
Copy link
Contributor Author

I wonder why the build failed, but mostly why the target is aarch64-apple-ios. I'm working on a M1Pro, target aarch64-apple-darwin, perhaps that was intended?

@mjpieters
Copy link
Contributor Author

Quick review assistance notes:

  • my (merged) PR Use style_text to style group header #319 fix to handle group header styling is already included in this PR.
  • I moved dark/light handling into the style_text method because the old approach of using .green() / .red() / ... methods is easily forgotten when writing new code. The style_text() method can trivially handle picking the right colours without developers of other areas of the code needing to remember.

@mjpieters
Copy link
Contributor Author

I wonder why the build failed, but mostly why the target is aarch64-apple-ios. I'm working on a M1Pro, target aarch64-apple-darwin, perhaps that was intended?

Ah, no, it's more of a general issue with the rust toolchain, as the same issues appeared on the main branch.

@Nukesor
Copy link
Owner

Nukesor commented Jul 5, 2022

Thanks for your contribution!

Yes, the CI seems to be broken for mac due to some changes in Rust v1.62.
I'll have a detailed look at your PR as soon as I find some time. I already took a first glance and the changes looked quite intuitive :)

@mjpieters
Copy link
Contributor Author

Yes, the CI seems to be broken for mac due to some changes in Rust v1.62.

Could you elaborate? I created the PR using 1.62 on a Mac (Macbook Pro 16", M1 Pro CPU, on macos 12.14). I see no issues, but I didn't test every feature either.

I'll have a detailed look at your PR as soon as I find some time. I already took a first glance and the changes looked quite intuitive :)

I'll go over it once more as I see that some of the client/display/state code uses comfy-table directly, which means that my changes to how the dark-theme colours are used may be affected.

@mjpieters
Copy link
Contributor Author

I'll go over it once more as I see that some of the client/display/state code uses comfy-table directly, which means that my changes to how the dark-theme colours are used may be affected.

I did indeed break dark styles for tables; I see two options to remedy this:

  • Revert the part of my refactor where the OutputStyle struct takes over swapping colours, putting the responsibility back on any code using colours.
  • Add a style_cell() method to the struct that lets you create styled comfy-table cells.

I'd pick the latter myself, so I'll just update the middle commit to do that. The other option would be to drop that commit.

@mjpieters
Copy link
Contributor Author

mjpieters commented Jul 6, 2022

So, the iOS build failure there was due to the cross-compilation toolchain not being installed, I fixed this in this PR by adding an extra commit that adds a target: line. :-)

I'll make that a separate PR against master, and I've removed the commit from this PR.

Now, the PR build with the commit fails on the clippy issues you already fixed on master :-P

@mjpieters mjpieters force-pushed the cli-color-option branch 2 times, most recently from fbf8696 to 578f690 Compare July 6, 2022 17:35
@codecov-commenter
Copy link

codecov-commenter commented Jul 6, 2022

Codecov Report

Merging #320 (adb59fb) into development (271b690) will decrease coverage by 0.13%.
The diff coverage is 1.18%.

@@               Coverage Diff               @@
##           development     #320      +/-   ##
===============================================
- Coverage        53.13%   52.99%   -0.14%     
===============================================
  Files               70       70              
  Lines             4705     4721      +16     
===============================================
+ Hits              2500     2502       +2     
- Misses            2205     2219      +14     
Impacted Files Coverage Δ
client/client.rs 0.00% <0.00%> (ø)
client/commands/format_state.rs 0.00% <0.00%> (ø)
client/commands/wait.rs 0.00% <0.00%> (ø)
client/display/group.rs 0.00% <0.00%> (ø)
client/display/helper.rs 0.00% <0.00%> (ø)
client/display/log/local.rs 0.00% <0.00%> (ø)
client/display/log/mod.rs 0.00% <0.00%> (ø)
client/display/log/remote.rs 0.00% <0.00%> (ø)
client/display/mod.rs 0.00% <0.00%> (ø)
client/display/state.rs 0.00% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 271b690...adb59fb. Read the comment docs.

@mjpieters
Copy link
Contributor Author

Is the Windows test failure a flakey test? It also failed for a build of my toolchain PR but not when that PR was merged, but there the windows build was cancelled due to a codecov upload failure.

@Nukesor
Copy link
Owner

Nukesor commented Jul 14, 2022

@mjpieters Yep, the windows test is a flaky one :D There's already an open ticket on this:

#315

I tried to increase the wait threshold several times, but this seems a different problem at hand. The original implementor of the windows code didn't came up with a fix either and just suggested to increase the wait threshold.

client/client.rs Outdated Show resolved Hide resolved
client/display/style.rs Outdated Show resolved Hide resolved
client/display/state.rs Outdated Show resolved Hide resolved
@Nukesor
Copy link
Owner

Nukesor commented Jul 16, 2022

Thanks again for your contributions! I'm always very happy when I get such high-quality contributions!

I'm also impressed by your detailed review and improvement of this project's CI! I definitely learned a few new things :)

Much appreciated!

@Nukesor
Copy link
Owner

Nukesor commented Jul 16, 2022

FYI I decided to ignore the flaky windows test for now.

Previously it only occurred every now and then, but recently it showed up much more consistently. My initial assuption would be that this has something to do with the current load on the Github's windows CI machines.

This consolidates output style responsibility into a single struct.

- Rename the Color struct to OutputStyle
- Rename the module to 'style'
- Move the 'style_text' helper into a method on OutputStyle
- Update all uses to use `style` as the variable name.
- Remove the red/green/yellow/white methods, and instead have style_text swap
  out colours when styling.
- Add a styled_cell method to ensure all Comfy-table output is following the
  same rules.
The default 'auto' enables styled output when connected to a tty. The
other options are 'always' and 'never'.
Copy link
Contributor Author

@mjpieters mjpieters left a comment

Choose a reason for hiding this comment

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

This is your project, so I'll happily follow your style here.

And I agree that the Cell:new() API is cleaner. I didn't want to completely replicate that API (return a custom Cell struct which ignores chained fg() and add_attribute() calls when colours are disabled), perhaps this is something that the upstream comfy_table project should provide.

@Nukesor
Copy link
Owner

Nukesor commented Jul 17, 2022

Review adjustments look good to me :)
I also tested the changes manually and everything worked just as expected.

Thanks again for your contribution!

I'll try to release a minor version in the near future :)

@Nukesor Nukesor merged commit 910a333 into Nukesor:development Jul 17, 2022
@mjpieters mjpieters deleted the cli-color-option branch October 17, 2022 14:17
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.

None yet

3 participants