Comparison

util/human/io.lua @ 13047:d939bf469057

util.human.io: Prefer using the $COLUMNS environment variable if set (by readline) Feels like it should be faster.
author Kim Alvefur <zash@zash.se>
date Fri, 07 Apr 2023 13:42:20 +0200
parent 13045:da0b3cb9a2ec
child 13048:946442df65d3
comparison
equal deleted inserted replaced
13046:4c3dc767fb11 13047:d939bf469057
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";
113 if env_cols then return env_cols; end
112 local stty = io.popen("stty -a"); 114 local stty = io.popen("stty -a");
113 if not stty then return default; end 115 if not stty then return default; end
114 local result = stty:read("*a"); 116 local result = stty:read("*a");
115 if result then 117 if result then
116 result = result:match("%f[%w]columns[ =]*(%d+)"); 118 result = result:match("%f[%w]columns[ =]*(%d+)");