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: Support row and cell-level style overrides #10

Open
erhhung opened this issue Jul 28, 2023 · 5 comments
Open

Feature: Support row and cell-level style overrides #10

erhhung opened this issue Jul 28, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@erhhung
Copy link

erhhung commented Jul 28, 2023

Introduce Row and Cell classes to allow customizing per-row and per-cell styling (alignment, color, and style). This is useful, for example, to highlight specific rows or specific cell values in a large table using, e.g., style="reverse"

# proposed syntax only!
table.add(Row(["hello-world", "1.0.0", "2023-07-28"], style="reverse")) #  row-level override
table.add(Row([Cell("foo-bar", style="bold"), "0.1.0", "2023-07-28"]))  # cell-level override
@petercorke
Copy link
Owner

thanks for the various issues and sorry for being slow, ansitable is probably due some TLC.

The Row and Cell ideas are interesting. At the moment the cell styling is done is a weak way with magic text. What does Row give beyond adding style arguments to table.add?

@petercorke
Copy link
Owner

If you've fixed any of these issues please share a PR. They are good points, and hopefully I can get some time to get back into this before end of year.

@petercorke
Copy link
Owner

OK, the row level override now exists, trailing arguments passed to row().

Am thinking of a few mechanisms to highlight specific cells in a row, perhaps something like:

table.row(*list, highlight=[Cell(0, bgcolor="red"), Cell(1, style="bold")])

which would require a new class Cell.

@petercorke petercorke added the enhancement New feature or request label May 22, 2024
@erhhung
Copy link
Author

erhhung commented May 22, 2024

I think separating the individual cell values from another highlight array that provides cell overrides is not very clean.

A common use case is to highlight an entire row, meaning the color and bgcolor is consistent across all cells of that row. So if I'm calling table.row(*list), I'd expect an intuitive list of optional args (e.g. color and bgcolor) that would apply the same style all cells of that row.

If I wanted to override the styling of specific cells in a row, then calling table.row(Cell("foo", color="red"), "bar", Cell("baz", bgcolor="yellow", style="underlined")) would be more appropriate, IMO.

@petercorke
Copy link
Owner

The common use case is now implemented, you can now set fgcolor, bgcolor and style for a row that override columnise settings.

Your syntax is elegant, thanks for the suggestion. I will go that way.

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

No branches or pull requests

2 participants