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

API changes #27

Merged
merged 11 commits into from
Nov 7, 2023
Merged

API changes #27

merged 11 commits into from
Nov 7, 2023

Conversation

tertsdiepraam
Copy link
Member

@tertsdiepraam tertsdiepraam commented Oct 31, 2023

Closes #25
Closes #26

Ultimately, I want to refine the API even more, but I think this is a pretty good step in the right direction. Note how all the tests and examples are now more declarative. The grid values never have to be mutable anymore.

There is a bit of an ugly thing, which is that dimensions is set to some unused dummy value before it is modified. We could refactor this internally with some TempGrid or something, but I wanted to focus this PR on the API.

Note that (as mentioned in #26) this PR removes the ability to use fit_into_columns.

cc @PThorpe92

The corresponding change in uutils ls would look like this: https://github.com/uutils/coreutils/pull/5485/files

Removes ability to fit into columns. All cells must be given up front. The
`Display` type is removed.

This comment was marked as outdated.

In uutils, we always fall back on printing everything in a single column
if the width is too small, so we simply use that as the default.
@PThorpe92
Copy link

Those codecov warnings make it really frustrating to look at diffs lol

Thanks for working with us on this. I'm testing this out now 👍

@tertsdiepraam
Copy link
Member Author

image
You can turn the annotations off here!

Thanks for testing it out!

Copy link

@PThorpe92 PThorpe92 left a comment

Choose a reason for hiding this comment

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

Looks great!

@tertsdiepraam
Copy link
Member Author

Thanks for testing!

I'll quickly mention that I want to do another iteration at some point that's gonna make this more zero-copy as well, but I'm still thinking about how to do that cleanly.

@tertsdiepraam
Copy link
Member Author

Oops should have requested review instead of assigning :)

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

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

Good work :)

@tertsdiepraam
Copy link
Member Author

I'm exploring some more improvements right now. Specifically, if we implement a proper width calculation, we don't need Cell anymore. There's a couple implementations out there:

Both are already part of the coreutils dependency tree. I'm tempted to use textwraps implementation, because it seems to be quite fast, because it does not create a new string and ignores the meaning of the ANSI codes.

README.md Outdated Show resolved Hide resolved
examples/basic.rs Outdated Show resolved Hide resolved
@@ -474,7 +344,8 @@ impl fmt::Display for Display<'_> {

// Adapted from the unstable API:
// https://doc.rust-lang.org/std/primitive.usize.html#method.div_ceil
/// Division with upward rouding
// Can be removed on MSRV 1.70.
/// Division with upward rounding
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Division with upward rounding
// Division with upward rounding

for consistency

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea there was that the first few comments are internal, while the last one is the docstring. But it's not a public function, so I can make it consistent if you want.

Copy link
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

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

some nits, feel free to ignore them

@tertsdiepraam
Copy link
Member Author

tertsdiepraam commented Nov 2, 2023

Ok, @PThorpe92 I need you again :) I've made the pretty drastic change to remove Cell and I'm using the textwrap::core::display_width function to do the width calculation. This should hopefully remove the need to do any custom width calculations. It'd be great if you could confirm that this works for eza as well. Basically, you can now just give the Grid either &str or String and it should just work. It passes our test suite for ls at least, so I'm hopeful that it will work.

@tertsdiepraam
Copy link
Member Author

(I have to update the docs to reflect this still)

@tertsdiepraam
Copy link
Member Author

I've made even more changes and I think this would be enough for a new release. It passes both the uutils1 and eza2 test suites (huge thanks to @PThorpe92 for testing it!). But of course, these new changes still need to be reviewed.

Footnotes

  1. https://github.com/uutils/coreutils/pull/5485

  2. https://github.com/eza-community/eza/compare/main...PThorpe92:eza:main

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
examples/basic.rs Outdated Show resolved Hide resolved
examples/big.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
let last_in_row = x == self.dimensions.widths.len() - 1;

let col_width = self.dimensions.widths[x];
let padding_size = col_width - cell.width;
let padding_size = col_width - width;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line can lead to a panic with "attempt to subtract with overflow". For example, if you set width: 15 in the basic example.

Copy link
Member Author

@tertsdiepraam tertsdiepraam Nov 3, 2023

Choose a reason for hiding this comment

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

Should be fixed now! I set the width for the fallback to a single column incorrectly. Nice find! Btw, how did find this?

Choose a reason for hiding this comment

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

Right? damn I was gonna say... good catch lol

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tertsdiepraam I played a bit with the basic example and wanted to see what happens if the width is low/zero ;-)

@tertsdiepraam
Copy link
Member Author

I still need to fix some of those suggestions. I'll get to that soon. I agree with all of them :)

examples/basic.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

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

With the exception of the tiny detail in examples/basic.rs it looks good :)

@tertsdiepraam tertsdiepraam merged commit 9bb0ae8 into uutils:main Nov 7, 2023
7 of 9 checks passed
@allaboutevemirolive
Copy link

Hye, @tertsdiepraam ! With this pull request, does it mean issue #24 should be closed, and others can work with issue #5396?

@tertsdiepraam
Copy link
Member Author

tertsdiepraam commented Dec 1, 2023

@allaboutevemirolive If I recall correctly, that PR wasn't quite correct yet right? The functionality that we want with the tabs has not been implemented here yet, so if you still want to work on it, you can. Although, with all the refactoring that happened it might be easier to start over. Sorry for all those changes :)

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.

Removing fit_into_columns New API
5 participants