DenverCoder1/table2ascii

[feature Request] Support for row with less columns

aurkaxi opened this issue · 5 comments

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.

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.

I think your example case is pretty neat.

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.

This feature is now released in version 1.0.1

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