Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 12529:7dae6d29b71d
prosodyctl shell: Communicate width of terminal to mod_admin_shell
This lets it adjust the width of tables to the actual terminal width.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 30 May 2022 15:28:44 +0200 |
parent | 12506:d04f6f014636 |
child | 12536:a8cb1d7a98db |
comparison
equal
deleted
inserted
replaced
12528:8e780079a424 | 12529:7dae6d29b71d |
---|---|
131 local session = event.origin.shell_session; | 131 local session = event.origin.shell_session; |
132 if not session then | 132 if not session then |
133 session = console:new_session(event.origin); | 133 session = console:new_session(event.origin); |
134 event.origin.shell_session = session; | 134 event.origin.shell_session = session; |
135 end | 135 end |
136 | |
137 local default_width = 132; -- The common default of 80 is a bit too narrow for e.g. s2s:show(), 132 was another common width for hardware terminals | |
138 local margin = 2; -- To account for '| ' when lines are printed | |
139 session.width = (tonumber(event.stanza.attr.width) or default_width)-margin; | |
140 | |
136 local line = event.stanza:get_text(); | 141 local line = event.stanza:get_text(); |
137 local useglobalenv; | 142 local useglobalenv; |
138 | 143 |
139 local result = st.stanza("repl-result"); | 144 local result = st.stanza("repl-result"); |
140 | 145 |
217 local section = data:match("^help (%w+)"); | 222 local section = data:match("^help (%w+)"); |
218 if not section then | 223 if not section then |
219 print [[Commands are divided into multiple sections. For help on a particular section, ]] | 224 print [[Commands are divided into multiple sections. For help on a particular section, ]] |
220 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] | 225 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] |
221 print [[]] | 226 print [[]] |
222 local row = format_table({ { title = "Section"; width = 7 }; { title = "Description"; width = "100%" } }) | 227 local row = format_table({ { title = "Section", width = 7 }, { title = "Description", width = "100%" } }, session.width) |
223 print(row()) | 228 print(row()) |
224 print(row { "c2s"; "Commands to manage local client-to-server sessions" }) | 229 print(row { "c2s"; "Commands to manage local client-to-server sessions" }) |
225 print(row { "s2s"; "Commands to manage sessions between this server and others" }) | 230 print(row { "s2s"; "Commands to manage sessions between this server and others" }) |
226 print(row { "http"; "Commands to inspect HTTP services" }) -- XXX plural but there is only one so far | 231 print(row { "http"; "Commands to inspect HTTP services" }) -- XXX plural but there is only one so far |
227 print(row { "module"; "Commands to load/reload/unload modules/plugins" }) | 232 print(row { "module"; "Commands to load/reload/unload modules/plugins" }) |
339 for column, spec in pairs(available_columns) do | 344 for column, spec in pairs(available_columns) do |
340 meta_columns[1].width = math.max(meta_columns[1].width or 0, #column); | 345 meta_columns[1].width = math.max(meta_columns[1].width or 0, #column); |
341 meta_columns[2].width = math.max(meta_columns[2].width or 0, #(spec.title or "")); | 346 meta_columns[2].width = math.max(meta_columns[2].width or 0, #(spec.title or "")); |
342 meta_columns[3].width = math.max(meta_columns[3].width or 0, #(spec.description or "")); | 347 meta_columns[3].width = math.max(meta_columns[3].width or 0, #(spec.description or "")); |
343 end | 348 end |
344 local row = format_table(meta_columns, 120) | 349 local row = format_table(meta_columns, session.width) |
345 print(row()); | 350 print(row()); |
346 for column, spec in iterators.sorted_pairs(available_columns) do | 351 for column, spec in iterators.sorted_pairs(available_columns) do |
347 print(row({ column, spec.title, spec.description })); | 352 print(row({ column, spec.title, spec.description })); |
348 end | 353 end |
349 print [[]] | 354 print [[]] |
933 end | 938 end |
934 | 939 |
935 function def_env.c2s:show(match_jid, colspec) | 940 function def_env.c2s:show(match_jid, colspec) |
936 local print = self.session.print; | 941 local print = self.session.print; |
937 local columns = get_colspec(colspec, { "id"; "jid"; "ipv"; "status"; "secure"; "smacks"; "csi" }); | 942 local columns = get_colspec(colspec, { "id"; "jid"; "ipv"; "status"; "secure"; "smacks"; "csi" }); |
938 local row = format_table(columns, 120); | 943 local row = format_table(columns, self.session.width); |
939 | 944 |
940 local function match(session) | 945 local function match(session) |
941 local jid = get_jid(session) | 946 local jid = get_jid(session) |
942 return (not match_jid) or jid == match_jid; | 947 return (not match_jid) or jid == match_jid; |
943 end | 948 end |
1016 end | 1021 end |
1017 | 1022 |
1018 function def_env.s2s:show(match_jid, colspec) | 1023 function def_env.s2s:show(match_jid, colspec) |
1019 local print = self.session.print; | 1024 local print = self.session.print; |
1020 local columns = get_colspec(colspec, { "id"; "host"; "dir"; "remote"; "ipv"; "secure"; "s2s_sasl"; "dialback" }); | 1025 local columns = get_colspec(colspec, { "id"; "host"; "dir"; "remote"; "ipv"; "secure"; "s2s_sasl"; "dialback" }); |
1021 local row = format_table(columns, 132); | 1026 local row = format_table(columns, self.session.width); |
1022 | 1027 |
1023 local function match(session) | 1028 local function match(session) |
1024 local host, remote = get_s2s_hosts(session); | 1029 local host, remote = get_s2s_hosts(session); |
1025 return not match_jid or host == match_jid or remote == match_jid; | 1030 return not match_jid or host == match_jid or remote == match_jid; |
1026 end | 1031 end |
1554 local print = self.session.print; | 1559 local print = self.session.print; |
1555 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); | 1560 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); |
1556 local output = format_table({ | 1561 local output = format_table({ |
1557 { title = "Module", width = "20%" }, | 1562 { title = "Module", width = "20%" }, |
1558 { title = "URL", width = "80%" }, | 1563 { title = "URL", width = "80%" }, |
1559 }, 132); | 1564 }, self.session.width); |
1560 | 1565 |
1561 for _, host in ipairs(hosts) do | 1566 for _, host in ipairs(hosts) do |
1562 local http_apps = modulemanager.get_items("http-provider", host); | 1567 local http_apps = modulemanager.get_items("http-provider", host); |
1563 if #http_apps > 0 then | 1568 if #http_apps > 0 then |
1564 local http_host = module:context(host):get_option_string("http_host"); | 1569 local http_host = module:context(host):get_option_string("http_host"); |