summary refs log tree commit diff stats
path: root/plugins/python
diff options
context:
space:
mode:
authorlinuxdaemon <linuxdaemon@users.noreply.github.com>2018-12-26 16:15:25 -0600
committerTingPing <tingping@tingping.se>2018-12-26 17:15:25 -0500
commitf7713a6a64ee55d3c20e9e27b8f8a5e98385ff57 (patch)
tree904cdd3115be7cc5434e9af84469153b2e070066 /plugins/python
parent3ebfa83fdd43335da1dd2d39f0bfae91d67b8c90 (diff)
python: Make the plugins table dynamically sized (#2291)
Adjust the width of the columns depending on the length of the data in
each element
Diffstat (limited to 'plugins/python')
-rw-r--r--plugins/python/python.py21
1 files changed, 17 insertions, 4 deletions
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'<none>'
         description = plugin.description.encode() if plugin.description else b'<none>'
-        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'')