hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Switch to table-layout for tabular layout

Open Xitian9 opened this issue 2 years ago • 6 comments

Fixes #1679. This gets rid of our home-customised Text.Tabular.AsciiWide and Text.WideString modules in favour of the external library table-layout.

At the moment this relies on a few PRs awaiting merge over at table-layout so it's probably not ready to be merged quite yet, but I'm putting it here for comment. I've broken it into several commits so that the changes are more bite-sized, but these changes are not atomic and tests will fail in the middle (mostly due to colouring negative amounts not being reintroduced until showMixedAmountB being updated), though it compiles at each step.

Xitian9 avatar Mar 29 '22 11:03 Xitian9

This PR would open the door to a number of potential improvements/customisations.

  • It would fairly easily allow aligning amounts on decimal points: https://github.com/muesli4/table-layout/issues/32
  • table-layout has a fairly robust table styling interface, and we could easily make our tables fancier, if that's the sort of thing we felt like doing. Here's an example of one of the fancier tables it can create (ignore github-induced gaps between lines)
╭───╥───────────────────┬───────────────────┬────────────┰────────────┬────────────┬────────────┬────────────┰────────────┬────────────╮
│   ║     Some text     │   Some numbers    │     X      ┃     Z      │     W      │     A      │     B      ┃    Text    │     Y      │
╞═══╬═══════════════════╪═══════════════════╪════════════╋════════════╧════════════╪════════════╧════════════╋════════════╧════════════╡
│ 1 ║ This is long text ┆    4.20000000     ┆    foo     ┃    blah         bloo    ┆    blop         blog    ┃   Short         baz     │
│   ║       Short       ┆ 200300400500600.2 ┆    bar     ┃   yadda         yoda    ┆   yeeda         york    ┃   Short        wibble   │
├───╫┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┄┄┄┄┄╂┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╂┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┤
│ 2 ║ This is long text ┆    4.20000000     ┆    foo     ┃  bibbidy      babbidy   ┆    boo          blue    ┃   Short        wobble   │
╰───╨───────────────────┴───────────────────┴────────────┸─────────────────────────┴─────────────────────────┸─────────────────────────╯

Xitian9 avatar Mar 30 '22 03:03 Xitian9

I know you already updated this a bunch of times, but when you get time could you do it once more and I'll review and merge if possible.

The hledger-lib/Text/WideString.hs utils are might be useful down the road, could we to keep them around a bit longer ?

As you saw in chat I would like to tweak table borders, adding consistent separators for totals. Maybe also using the same style for all borders, making life simpler (rather than adding more complex styling - but no harm to have that ability in the toolbox).

How could using table-layout help with decimal aligning ?

simonmichael avatar Oct 25 '22 09:10 simonmichael

How could using table-layout help with decimal aligning ?

"Align content in a column at a character occurence.", I see, nifty. Might be a bit tricky with our variable decimal marks..

simonmichael avatar Oct 25 '22 09:10 simonmichael

"Align content in a column at a character occurence.", I see, nifty. Might be a bit tricky with our variable decimal marks..

It's possible with a custom implementation of Cell. See here: https://github.com/muesli4/table-layout/issues/32

Xitian9 avatar Oct 25 '22 09:10 Xitian9

https://github.com/muesli4/table-layout/issues/43

simonmichael avatar Oct 25 '22 10:10 simonmichael