local colormt = {}
local ansicolors = {}
+local rspamd_util = require "rspamd_util"
+local isatty = rspamd_util.isatty()
+
function colormt:__tostring()
return self.value
end
end
colormt.__metatable = {}
-
local function makecolor(value)
- return setmetatable({ value = string.char(27) .. '[' .. tostring(value) .. 'm' }, colormt)
+ if isatty then
+ return setmetatable({
+ value = string.char(27) .. '[' .. tostring(value) .. 'm'
+ }, colormt)
+ else
+ return setmetatable({
+ value = ''
+ }, colormt)
+ end
end
local colors = {
*/
LUA_FUNCTION_DEF (util, umask);
+/***
+ * @function util.isatty()
+ * Returns if stdout is a tty
+ * @return {boolean} true in case of output being tty
+ */
+LUA_FUNCTION_DEF (util, isatty);
/***
* @function util.pack(fmt, ...)
LUA_INTERFACE_DEF (util, file_exists),
LUA_INTERFACE_DEF (util, mkdir),
LUA_INTERFACE_DEF (util, umask),
+ LUA_INTERFACE_DEF (util, isatty),
LUA_INTERFACE_DEF (util, get_hostname),
LUA_INTERFACE_DEF (util, pack),
LUA_INTERFACE_DEF (util, unpack),
return 1;
}
+static gint
+lua_util_isatty (lua_State *L)
+{
+ if (isatty (STDOUT_FILENO)) {
+ lua_pushboolean (L, true);
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+
+ return 1;
+}
+
/* Backport from Lua 5.3 */
/******************************************************************************