Software /
code /
prosody
Comparison
util/human/io.lua @ 13051:164c2787901a
util.human.io: Coerce $COLUMNS to number
os.getenv() returns a string but term_width() should return a number
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 07 Apr 2023 13:54:16 +0200 |
parent | 13049:115ce3ab5b8b |
child | 13054:f4d7fe919969 |
comparison
equal
deleted
inserted
replaced
13050:4ae759490e31 | 13051:164c2787901a |
---|---|
107 return s:sub(1, utf8.offset(s, pos+1)-1); | 107 return s:sub(1, utf8.offset(s, pos+1)-1); |
108 end | 108 end |
109 end | 109 end |
110 | 110 |
111 local function term_width(default) | 111 local function term_width(default) |
112 local env_cols = os.getenv "COLUMNS"; | 112 local env_cols = tonumber(os.getenv "COLUMNS"); |
113 if env_cols then return env_cols; end | 113 if env_cols then return env_cols; end |
114 local stty = io.popen("stty -a"); | 114 local stty = io.popen("stty -a"); |
115 if not stty then return default; end | 115 if not stty then return default; end |
116 local result = stty:read("*a"); | 116 local result = stty:read("*a"); |
117 if result then | 117 if result then |