Software /
code /
prosody
Changeset
12539:cfdc8cca64d3
util.prosodyctl.shell: Print errors in red to highlight them
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 01 Jun 2022 13:59:00 +0200 |
parents | 12538:0f56587bb37f |
children | 12540:0684506c99d3 |
files | util/prosodyctl/shell.lua |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/prosodyctl/shell.lua Tue May 31 13:26:44 2022 +0200 +++ b/util/prosodyctl/shell.lua Wed Jun 01 13:59:00 2022 +0200 @@ -4,6 +4,8 @@ local path = require "util.paths"; local parse_args = require "util.argparse".parse; local unpack = table.unpack or _G.unpack; +local tc = require "util.termcolours"; +local isatty = require "util.pposix".isatty; local have_readline, readline = pcall(require, "readline"); @@ -64,6 +66,7 @@ local function start(arg) --luacheck: ignore 212/arg local client = adminstream.client(); local opts, err, where = parse_args(arg); + local ttyout = isatty(io.stdout); if not opts then if err == "param-not-found" then @@ -122,7 +125,11 @@ client.events.add_handler("received", function (stanza) if stanza.name == "repl-output" or stanza.name == "repl-result" then local result_prefix = stanza.attr.type == "error" and "!" or "|"; - print(result_prefix.." "..stanza:get_text()); + local out = result_prefix.." "..stanza:get_text(); + if ttyout and stanza.attr.type == "error" then + out = tc.getstring(tc.getstyle("red"), out); + end + print(out); end if stanza.name == "repl-result" then repl(client);