Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Set table width #29

Open
Nekmo opened this issue May 28, 2016 · 3 comments
Open

Set table width #29

Nekmo opened this issue May 28, 2016 · 3 comments

Comments

@Nekmo
Copy link

Nekmo commented May 28, 2016

I have several tables and I'd like all have the same width.

pycharm_django_settings1

My idea is to get the size of the largest and set it on all tables, but there is no method to set the width.

@Robpol86
Copy link
Owner

Currently terminaltables doesn't wrap/truncate cells, so it doesn't set widths, widths depend on the strings in cells. Perhaps once I implement #5 I'll consider this.

@ashwanth10
Copy link

If too many columns are present, the columns just overwrite on the screen.
How about adding a scrollbar to CLI if too many columns come up?

@privatwolke
Copy link

This is a quick and dirty solution if the data across tables is somewhat consistent:

def equalize(tables):
    """ Equalizes the columns sizes across multiple tables. """
    lens = defaultdict(lambda: 0)
    for table in tables:
        for row in table:
            for idx, cell in enumerate(row):
                lens[idx] = max(lens[idx], len(cell))

    for tid, table in enumerate(tables):
        for rid, row in enumerate(table):
            for cid, cell in enumerate(row):
                tables[tid][rid][cid] = cell.ljust(lens[cid])

    return tables

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants