aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-07-16 21:21:37 +0200
committerKim Alvefur <zash@zash.se>2023-07-16 21:21:37 +0200
commitc222b08005a9a7e8e45bef8b074fd3ab12cd8a5f (patch)
tree0b1ab6a44becca094eb119f177a7d4a0b4e5e896 /util
parent1987a7411f6aab1b0534ef23dc8797362eae1076 (diff)
downloadprosody-c222b08005a9a7e8e45bef8b074fd3ab12cd8a5f.tar.gz
prosody-c222b08005a9a7e8e45bef8b074fd3ab12cd8a5f.zip
util.human.io: Fix stray 'stty' error by only querying width of real ttys
This adds a dependency on a binary and *nix-specific module but then stty is probably *nix-specific anyway so maybe that's fine.
Diffstat (limited to 'util')
-rw-r--r--util/human/io.lua4
1 files changed, 4 insertions, 0 deletions
diff --git a/util/human/io.lua b/util/human/io.lua
index 542e4ceb..5af8d13e 100644
--- a/util/human/io.lua
+++ b/util/human/io.lua
@@ -1,4 +1,5 @@
local array = require "prosody.util.array";
+local pposix = require "prosody.util.pposix";
local utf8 = rawget(_G, "utf8") or require"prosody.util.encodings".utf8;
local len = utf8.len or function(s)
local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", "");
@@ -111,6 +112,9 @@ end
local function term_width(default)
local env_cols = tonumber(os.getenv "COLUMNS");
if env_cols then return env_cols; end
+ if not pposix.isatty(io.stdout) then
+ return default;
+ end
local stty = io.popen("stty -a");
if not stty then return default; end
local result = stty:read("*a");