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

Hopefully fix unicodes and indented pretty printing #1581

Merged
merged 24 commits into from
Feb 16, 2024

Conversation

aaruni96
Copy link
Contributor

Fixes #1561

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (c563d60) 87.17% compared to head (be44068) 86.98%.
Report is 27 commits behind head on master.

Files Patch % Lines
src/PrettyPrinting.jl 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1581      +/-   ##
==========================================
- Coverage   87.17%   86.98%   -0.20%     
==========================================
  Files         115      114       -1     
  Lines       29565    29686     +121     
==========================================
+ Hits        25773    25822      +49     
- Misses       3792     3864      +72     

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

@thofma
Copy link
Member

thofma commented Jan 29, 2024

Thanks. I would like to see a bit more tests, things with non-standard width like '⛵' and where it has to wrap a line.

@aaruni96
Copy link
Contributor Author

Fixed the case where the spilled over line still had unicode.

Now looking into characters with non standard widths.

Copy link
Collaborator

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

Not getting weird errors from unicode chars getting ripped in half is already a great step IMO.
handling chars of different widths and still get visually a fixed with of x columns in the terminal is great to have, but I think much harder to implement. Thus I would be happy to merge as is (with a few more tests) and get everything else in a future PR.

@fingolfin
Copy link
Member

I agree 100% with @lgoettgens . I have zero issues with printing involving double width chars right now, but I've run into errors due to multibyte single width chars in two completely independent situations by now.

src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
@lgoettgens
Copy link
Collaborator

I think most of this could be written very nice and concise using the second dispatch (with UnitRange) of https://docs.julialang.org/en/v1/stdlib/Unicode/#Unicode.graphemes, but unfortunately this is only existent from julia 1.9. So maybe add a comment referencing this so we can rewrite once the compat bound is changed. Or we include the function for older versions ourselves

@aaruni96
Copy link
Contributor Author

I've found a strange bug already, while trying to write a test. Please do not merge this in its current state.

@fingolfin fingolfin marked this pull request as draft January 29, 2024 23:25
@fingolfin
Copy link
Member

I marked this as a "draft" PR for now :-)

@aaruni96 aaruni96 marked this pull request as ready for review January 30, 2024 10:37
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
Copy link
Collaborator

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

The code changes look very clean now after the refactoring. Thanks!

Whats left from the comments above: Can you add some tests using something with many combiners (like in #1581 (comment)) and something of non-standard width (like in #1581 (comment))?

@aaruni96
Copy link
Contributor Author

aaruni96 commented Feb 7, 2024

No longer crashes when graphemes of non standard width are encountered, but currently does not account for it while calculating when to line break.

I will add tests including wide graphemes along with the patch that makes them print in line with other characters.

According to alacritty/alacritty#265 (comment) , unicode in monospace can only have width 0, 1, or 2, so, just accounting for width 2 (in addition to what we already do) should be enough.
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Just had a quick look. The println(io) bit must be changed. I think the lowercasefirst handling should also be changed then as we need to re-run tests anyway, and it simplifies the code. Your choice about the iterators

src/PrettyPrinting.jl Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Show resolved Hide resolved
src/PrettyPrinting.jl Show resolved Hide resolved
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Tests look good but there are a few simple optimizations to be had, see the code suggestions. Other than that I am OK with merging this. Feel free to come over to my office to discuss any of these.

src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Outdated Show resolved Hide resolved
src/PrettyPrinting.jl Show resolved Hide resolved
@fingolfin fingolfin merged commit 3246a27 into Nemocas:master Feb 16, 2024
27 of 30 checks passed
@fingolfin
Copy link
Member

Thanks @aaruni96 !!!

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.

Pretty printing code (esp. indent) has issues with non-ASCII unicode strings
4 participants