cmck / python-tabulate

MIT License
5 stars 1 forks source link

less verbose grids #1

Open anarcat opened 4 years ago

anarcat commented 4 years ago

Hi!

I'd love to have a "less verbose" fancy grid layout. this, for example, seems counter-intuitive:

#!/usr/bin/python3

import tabulate

table = [["spam",42],["eggs",451],["bacon",0]]
headers = ["item", "qty"]

print(tabulate.tabulate(table, headers, tablefmt="simple"))
print(tabulate.tabulate(table, headers, tablefmt="fancy_grid"))
$ python3 ~/bin/test-tabulate.py 
item      qty
------  -----
spam       42
eggs      451
bacon       0
╒════════╤═══════╕
│ item   │   qty │
╞════════╪═══════╡
│ spam   │    42 │
├────────┼───────┤
│ eggs   │   451 │
├────────┼───────┤
│ bacon  │     0 │
╘════════╧═══════╛

ie. why are there separators between the lines in the second table and not the first? it makes tables really (needlessly, IMHO) long. i would prefer it like this:

#!/usr/bin/python3

import tabulate

table = [["spam",42],["eggs",451],["bacon",0]]
headers = ["item", "qty"]

fancy_grid_nogap = tabulate.TableFormat(lineabove=tabulate.Line("╒", "═", "╤", "╕"),
                                        linebelowheader=tabulate.Line("╞", "═", "╪", "╡"),
                                        linebetweenrows=None,
                                        linebelow=tabulate.Line("╘", "═", "╧", "╛"),
                                        headerrow=tabulate.DataRow("│", "│", "│"),
                                        datarow=tabulate.DataRow("│", "│", "│"),
                                        padding=1, with_header_hide=None)

print(tabulate.tabulate(table, headers, tablefmt="simple"))
print(tabulate.tabulate(table, headers, tablefmt=fancy_grid_nogap))
$ python3 ~/bin/test-tabulate.py 
item      qty
------  -----
spam       42
eggs      451
bacon       0
╒════════╤═══════╕
│ item   │   qty │
╞════════╪═══════╡
│ spam   │    42 │
│ eggs   │   451 │
│ bacon  │     0 │
╘════════╧═══════╛

and while, yes, i found out I can do that myself, I was wondering if you would welcome a PR that would do so. :)

thanks!

anarcat commented 4 years ago

in fact, i would very much prefer this:

            args.format = tabulate.TableFormat(lineabove=tabulate.Line("╔", "═", "╤", "╗"),
                                               linebelowheader=tabulate.Line("╠", "═", "╪", "╣"),
                                               linebetweenrows=None,
                                               linebelow=tabulate.Line("╚", "═", "╧", "╝"),
                                               headerrow=tabulate.DataRow("║", "│", "║"),
                                               datarow=tabulate.DataRow("║", "│", "║"),
                                               padding=1, with_header_hide=None)

which looks like this here:

$ repology get monkeysign
╔════════════════════╤════════════════╤══════════╗
║ repo               │ version        │ status   ║
╠════════════════════╪════════════════╪══════════╣
║ aur                │ 2.0.2          │ outdated ║
║ aur                │ 2.2.3.g37fabfe │ rolling  ║
║ debian_oldstable   │ 2.2.3          │ outdated ║
╚════════════════════╧════════════════╧══════════╝