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

Fill up rows as much as possible in LeftToRight direction #6

Open
tertsdiepraam opened this issue Nov 20, 2022 · 2 comments
Open

Fill up rows as much as possible in LeftToRight direction #6

tertsdiepraam opened this issue Nov 20, 2022 · 2 comments

Comments

@tertsdiepraam
Copy link
Member

Below is a test adapted from the test in ogham/rust-term-grid#15. It currently fails in this fork too.

#[test]
fn theoretical_is_effective_max_num_line() {
    let mut grid = Grid::new(GridOptions {
        filling: Filling::Text("||".into()),
        direction: Direction::LeftToRight,
    });

    for s in [
        "test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10",
        "test11",
    ] {
        grid.add(Cell::from(s));
    }

    let bits =
        "test1 ||test2 ||test3||test4||test5||test6||test7||test8||test9\ntest10||test11||\n";

    let display = grid.fit_into_width(69).unwrap();
    assert_eq!(display.to_string(), bits);
    assert_eq!(display.row_count(), 2);
}

Expected behaviour:

test1 ||test2 ||test3||test4||test5||test6||test7||test8||test9
test10||test11||

Actual behaviour:

test1||test2||test3||test4 ||test5 ||test6
test7||test8||test9||test10||test11||

This expected behaviour matches the behaviour of GNU ls:

❯ ls --sort=version -x
test1   test2   test3  test4  test5  test6  test7  test8  test9
test10  test11

However, this behaviour changes in the column format:

❯ ls --sort=version
test1  test3  test5  test7  test9   test11
test2  test4  test6  test8  test10

Note how it's not:

test1  test3  test5  test6 test7  test8  test9  test10  test11
test2  test4

We have three options to proceed:

  • Settle on one behaviour and document the difference with GNU in uutils/coreutils.
  • Make this behaviour configurable regardless of direction.
  • Make Direction::LeftToRight fill up as much of the lines and make Direction::TopToBottom fill up columns.

I'd like to coordinate also with the exa folks to determine whether they want to use this fork too and what behaviour they want.

@ariasuni
Copy link

I was very happy with my code because it’s much more simple than the current one, that I couldn’t understand it fully. I’d like to know what the algorithm is to get to the ls result, since it seems a bit more satisfying. Honestly I don’t really care about the behavior since I never use the grid view, as long as its somewhat sensible and fast.

@tertsdiepraam
Copy link
Member Author

I know what you mean, the code had become quite difficult. I'll see what I can take from your code to simplify the current implementation. Thanks for your input!

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

No branches or pull requests

2 participants