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

[feature Request] Support for row with less columns #59

Closed
aurkaxi opened this issue Dec 4, 2022 · 5 comments · Fixed by #67
Closed

[feature Request] Support for row with less columns #59

aurkaxi opened this issue Dec 4, 2022 · 5 comments · Fixed by #67
Labels
enhancement New feature or request

Comments

@aurkaxi
Copy link

aurkaxi commented Dec 4, 2022

if first row has 3 all rows have to have 3 columns. Is it possible to add a new row with 2 columns? currently not. in future?
image

Here the last row, has two columns: Description and
i edited the text to show.

@DenverCoder1 DenverCoder1 added the enhancement New feature or request label Dec 5, 2022
@DenverCoder1
Copy link
Owner

DenverCoder1 commented Dec 5, 2022

It's not so clear what the default behavior should be when the number of columns does not match.

There should ideally be an API for choosing which columns get merged in each row since in other cases you may want different cells to be merged into one, and not always just all the cells until the end of the row.

It's hard to come up with a very customizable interface that's also simple to use.

One solution could be to have a unique value to represent merging with the cell on the left, eg.

table2ascii(
    body=[
        [1, 2, 3, 4, 5],
        ["A", "Long cell value", MERGE_LEFT, MERGE_LEFT, MERGE_LEFT ]
    ]
)

I'm not sure how common the use case is, let me know what your thoughts are on how it should be implemented for the user.

@aurkaxi
Copy link
Author

aurkaxi commented Dec 10, 2022

I think your example case is pretty neat.

@DenverCoder1
Copy link
Owner

DenverCoder1 commented Dec 12, 2022

I've created a branch at https://github.com/DenverCoder1/table2ascii/tree/merge with what I've tried out.

You should be able to test it with pip install -U git+https://github.com/DenverCoder1/table2ascii.git@merge

For your example, it should work just fine.

from table2ascii import table2ascii
from table2ascii.merge import Merge
from table2ascii.alignment import Alignment
from table2ascii.preset_style import PresetStyle

output = table2ascii(
    header=["Name", "Price", "Category", "Stock", "Sku"],
    body=[
        ["test", 443, "test", 67, "test"],
    ],
    footer=["Description", "Long cell value that is merged", Merge.LEFT, Merge.LEFT, Merge.LEFT],
    alignments=[Alignment.LEFT] * 5,
    style=PresetStyle.thin_thick_rounded,
)

print(output)

image

output = table2ascii(
    header=["Name", "Price", "Category", "Stock", "Sku"],
    body=[
        ["test", 443, "test", 67, "test"],
    ],
    footer=["Description", "Long cell value that is merged and wraps to multiple lines", Merge.LEFT, Merge.LEFT, Merge.LEFT],
    alignments=[Alignment.LEFT] * 5,
    style=PresetStyle.thin_thick_rounded,
)

image

After some more testing, it will likely make it into the next release.

@DenverCoder1
Copy link
Owner

This feature is now released in version 1.0.1

@aurkaxi
Copy link
Author

aurkaxi commented Dec 18, 2022

Thanks, This may be the only one program in this category which allows this. Thanks again for considering my request. I honor you.

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

Successfully merging a pull request may close this issue.

2 participants