Open dgw opened 1 year ago
I started thinking about this again today, where the original motivation was to add a version field into sopel-plugins list
output. Still, it all blends together into a jumble of characters.
With some playing around, I got a reasonable-looking output just using Python's built-in string formatting mini-language:
The relevant code for this would be:
version = description['version']
description['version'] = 'v' + version if version else 'unknown'
template = '{name:<24} {version:<8} {status:<10} {type:<16} {source:<32} {label}'
No doubt, this could be made even prettier with some other tools, possibly a library like tabulate
or columnar
—but for only using stdlib and not modifying the code to generate a list of tuples first (so optimal widths could be calculated based on the longest string in each column before output) I think it's already pretty good.
Am not ready to really start working on this and open a PR, so I figured leaving my code snippet in a comment here would be good enough.
I found myself very frustrated this week, trying to read the output of
sopel-plugins list
because all the different bits of data blend together. Converting to (or adding) a tabular view for this command would be a nice feature for 8.0, if I can find time to play with it before Python 3.7 dies and the other maintainers start sharpening their spears.Other CLI commands' output might benefit from a revisit, too; I just can't play with the CLI too much right now because I'm in a meeting. Getting this idea down was my priority. 😅
Relevant code is near here:
https://github.com/sopel-irc/sopel/blob/d84ffb277a13f459f9a600f8a625612b6f809ac2/sopel/cli/plugins.py#L234