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

feat: added a custom writer for all text printers #324

Conversation

Brookke
Copy link
Contributor

@Brookke Brookke commented Mar 17, 2022

Description

Add custom writer support for most of the printers except for the area_printer

Scope

What is affected by this pull request?

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Related Issue

Fixes #261

To-Do Checklist

  • I tested my changes
  • I have commented every method that I created/changed
  • I updated the examples to fit with my changes
  • I have added tests for my newly created methods

@Brookke Brookke force-pushed the issue-261-Add_ability_to_set_custom_io_writter_for_each_of_the_different_output_levels branch from fd47a90 to 1070040 Compare March 17, 2022 16:54
@github-actions github-actions bot added feature and removed feature labels Mar 17, 2022
@MarvinJWendt
Copy link
Member

Hi @Brookke, just a quick info: The snapshot testing is currently behaving a little weird, so the Build action will most likely always fail. If your local test runs succeed, it's fine. I will fix the tests for this PR when you're ready :)

@Brookke
Copy link
Contributor Author

Brookke commented Mar 17, 2022

Hi @Brookke, just a quick info: The snapshot testing is currently behaving a little weird, so the Build action will most likely always fail. If your local test runs succeed, it's fine. I will fix the tests for this PR when you're ready :)

Seeing a similar snapshot failure locally too, so I will try and get that sorted

@codecov
Copy link

codecov bot commented Mar 17, 2022

Codecov Report

Merging #324 (48050e3) into master (091ef5d) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #324   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         1473      1505   +32     
=========================================
+ Hits          1473      1505   +32     
Impacted Files Coverage Δ
barchart.go 100.00% <100.00%> (ø)
basic_text_printer.go 100.00% <100.00%> (ø)
bigtext_printer.go 100.00% <100.00%> (ø)
box_printer.go 100.00% <100.00%> (ø)
bulletlist_printer.go 100.00% <100.00%> (ø)
center_printer.go 100.00% <100.00%> (ø)
header_printer.go 100.00% <100.00%> (ø)
panel_printer.go 100.00% <100.00%> (ø)
paragraph_printer.go 100.00% <100.00%> (ø)
prefix_printer.go 100.00% <100.00%> (ø)
... and 6 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 091ef5d...48050e3. Read the comment docs.

@Brookke
Copy link
Contributor Author

Brookke commented Mar 17, 2022

@MarvinJWendt When you get a moment in the next few days mind giving this a partial review. What this PR does is builds upon Florians previous work, however rather than setting a default io.Writer for every printer it leaves them as nil, and simply falls back to the default one set in color if the writer is nil, this way the existing tests all still work as expected and it remains backwards compatible.

If you are happy with this approach I will then move on to start writing tests for each of the new WithCustomWriter functions.

The only thing I am not super confident about are the writer check lines here: https://github.com/pterm/pterm/pull/324/files#diff-a771b53b10418ad32cd676b8f07bed1b1bd9bbc7ee430bec4b7172c0de679e61R109 however I will try to do some local testing on these to see if this works as expected.

@Brookke
Copy link
Contributor Author

Brookke commented Mar 17, 2022

The only thing I am not super confident about are the writer check lines here: https://github.com/pterm/pterm/pull/324/files#diff-a771b53b10418ad32cd676b8f07bed1b1bd9bbc7ee430bec4b7172c0de679e61R109 however I will try to do some local testing on these to see if this works as expected.

upon second thoughts I remember we said I'd deal with this in a second PR so I will remove the LivePrinters ability to use a custom writer

@MarvinJWendt
Copy link
Member

I will review this shorty!
I am currently removing the snapshot tests, they are just way too buggy at the moment, and trigger more false positives than real failures. This will make testing easier for you too :)

@MarvinJWendt
Copy link
Member

Snapshot testing is now removed.

Note: if you use any JetBrains IDE (IntelliJ IDEA, GoLand, etc.) you should commit and push your changes before pulling master into your branch, as we also removed the .idea folder from the repo, which will result in IntelliJ breaking. The fix is to re-clone the project and it should just work fine again. as IntelliJ will re-generate the folder locally then.

Copy link
Member

@MarvinJWendt MarvinJWendt left a comment

Choose a reason for hiding this comment

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

Looks very good! I have noted a small change (rename WithCustomWriter to WithWriter), but that's all. Awesome work, thanks a lot!

Oh one small thing, when you're done, please also update the docs for https://pterm.sh by editing /docs/printers/*. Just append the new functions to the list, that should be enough!

basic_text_printer.go Outdated Show resolved Hide resolved
Comment on lines -49 to +58
// Print formats using the default formats for its operands and writes to standard output.
// Print formats using the default formats for its operands and writes to provided writer.
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@Brookke
Copy link
Contributor Author

Brookke commented Mar 18, 2022

I will review this shorty!
I am currently removing the snapshot tests, they are just way too buggy at the moment, and trigger more false positives than real failures. This will make testing easier for you too :)

For what it's worth I thought the snapshot testing had some value as it did catch some of the issues I had, and they did run locally and pass for me. The main issue I had with them is that they would keep creating snapshot files each time I ran then and I would have to clear those between tests.

@MarvinJWendt
Copy link
Member

I will review this shorty!
I am currently removing the snapshot tests, they are just way too buggy at the moment, and trigger more false positives than real failures. This will make testing easier for you too :)

For what it's worth I thought the snapshot testing had some value as it did catch some of the issues I had, and they did run locally and pass for me. The main issue I had with them is that they would keep creating snapshot files each time I ran then and I would have to clear those between tests.

In a few cases PTerm renders different output in the CI systems than locally, which has caused just about every CI run to fail. I am planning a bigger refactor, we'll probably add it back then!

@MarvinJWendt
Copy link
Member

MarvinJWendt commented Mar 22, 2022

Hi @Brookke, is the PR ready for review? If so, please mark it as "Ready for review" :)

@Brookke
Copy link
Contributor Author

Brookke commented Mar 23, 2022

Sorry haven't added any tests yet, let me try and get those sorted tomorrow!

@Brookke Brookke force-pushed the issue-261-Add_ability_to_set_custom_io_writter_for_each_of_the_different_output_levels branch from 6dc4bf2 to 28fd8c1 Compare March 23, 2022 18:27
@Brookke Brookke force-pushed the issue-261-Add_ability_to_set_custom_io_writter_for_each_of_the_different_output_levels branch from dc5ead7 to bcf821b Compare March 23, 2022 18:49
@Brookke Brookke marked this pull request as ready for review March 23, 2022 18:49
@Brookke Brookke force-pushed the issue-261-Add_ability_to_set_custom_io_writter_for_each_of_the_different_output_levels branch from bcf821b to 48050e3 Compare March 23, 2022 18:50
@Brookke
Copy link
Contributor Author

Brookke commented Mar 23, 2022

Okay should be good to go now

Copy link
Member

@MarvinJWendt MarvinJWendt left a comment

Choose a reason for hiding this comment

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

Description Passed
Every WithXXX(...) function returns a pointer of the parent struct. YES
Test contains nil check. YES
Printers implement the right interface. YES
Variable and function names describe what they do. YES
Printer contains theme support. N/A
Styles in structs must be pointers. N/A
Printer tests uses correct test template. YES
Commit messages follow conventional commit style. If NO -> Squash NO
Possible errors are declared in the errors.go file. N/A
Theme styles do not return pointers N/A
Documentation in ./docs is updated correctly. YES

@MarvinJWendt
Copy link
Member

Looks very good! Huge thanks for the contribution! I am currently doing some tests with it locally. If everything works as expected (I highly doubt it won't), it will be released today! I also gave you the contributor role in our Discord 😉

@MarvinJWendt MarvinJWendt merged commit dc10c49 into pterm:master Mar 28, 2022
@MarvinJWendt MarvinJWendt changed the title feat: added a custom writer for all printers feat: added a custom writer for all text printers Mar 28, 2022
@github-actions github-actions bot added feature and removed feature labels Mar 28, 2022
@MarvinJWendt
Copy link
Member

Hi @Brookke, sorry the release will be a little delayed. GitHub Pages won't build, and after talking to the GitHub Support, it seems that they're having issues.

image

As soon as the docs site is up, the release will be made!

@Brookke
Copy link
Contributor Author

Brookke commented Mar 28, 2022

Thank you! No rush ☺️

@Brookke Brookke deleted the issue-261-Add_ability_to_set_custom_io_writter_for_each_of_the_different_output_levels branch March 28, 2022 20:06
@MarvinJWendt
Copy link
Member

Released in v0.12.40! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to set custom io.writter for each of the different output levels
3 participants