muesli4 / table-layout

Layout data in grids and pretty tables. Provides a lot of tools to get the cell formatting right (positional alignment, alignment on specific characters and limiting of cell width)..
BSD 3-Clause "New" or "Revised" License
37 stars 11 forks source link

Implement DropAction #58

Open Xitian9 opened 11 months ago

Xitian9 commented 11 months ago

This separates the measurement phase from the building phase.

The tests currently fail, but I'm putting this up as draft to solicit feedback on whether this was what you had in mind. The reasons test fail is that buildCell $ dropLeft n s is no longer guaranteed to have the expected width, since it will no longer add padding to get up to the expected width. Correcting this is either a matter of changing the trimming logic elsewhere, or reimplementing the padding logic for now.

Xitian9 commented 11 months ago

There's a question of whether we should require a Monoid instance for all DropActions. This is necessary in order to define a Cell instance for Formatted, but doesn't strictly have to be part of the class definition.

Option 1: class (Monoid (DropAction a)) => Cell a

Advantages

Disadvantages

Option 2: instance (Monoid (DropAction a), Cell a) => Cell (Formatted a)

Alternatively, we could leave it out of the class definition and just add it in to the instance declaration instance (Monoid (DropAction a), Cell a) => Cell (Formatted a).

Advantages

Disadvantages

I think option 1 has the advantage of being conceptually cleaner and with cleaner code, at the cost of a tiny bit of boilerplate for instance definers (which is probably a good idea to do anyway). The fact that option 2 requires UndecidableInstances is a big point against it in my opinion, and I'd strongly recommend the former.

Xitian9 commented 10 months ago

I'll have some free time over the next couple of weeks, if you wanted to make suggestions.

muesli4 commented 8 months ago

I'm sorry to leave you hanging again. I know exactly what it feels like from your perspective and it is unfair. Basically any change that takes me more than an hour to review is difficult. I can't make any promises there.