From f7713a6a64ee55d3c20e9e27b8f8a5e98385ff57 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Wed, 26 Dec 2018 16:15:25 -0600 Subject: python: Make the plugins table dynamically sized (#2291) Adjust the width of the columns depending on the length of the data in each element --- plugins/python/python.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'plugins/python/python.py') diff --git a/plugins/python/python.py b/plugins/python/python.py index 942b0ce5..371fbf40 100644 --- a/plugins/python/python.py +++ b/plugins/python/python.py @@ -349,15 +349,28 @@ def list_plugins(): lib.hexchat_print(lib.ph, b'No python modules loaded') return - lib.hexchat_print(lib.ph, b'Name Version Filename Description') - lib.hexchat_print(lib.ph, b'---- ------- -------- -----------') + tbl_headers = [b'Name', b'Version', b'Filename', b'Description'] + tbl = [ + tbl_headers, + [(b'-' * len(s)) for s in tbl_headers] + ] + for plugin in plugins: basename = os.path.basename(plugin.filename).encode() name = plugin.name.encode() version = plugin.version.encode() if plugin.version else b'' description = plugin.description.encode() if plugin.description else b'' - string = b'%-12s %-8s %-20s %-10s' %(name, version, basename, description) - lib.hexchat_print(lib.ph, string) + tbl.append((name, version, basename, description)) + + column_sizes = [ + max(len(item) for item in column) + for column in zip(*tbl) + ] + + for row in tbl: + lib.hexchat_print(lib.ph, b' '.join(item.ljust(column_sizes[i]) + for i, item in enumerate(row))) + lib.hexchat_print(lib.ph, b'') -- cgit 1.4.1